Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default locale can't handle values for repeaters in templatefields #156

Open
SantinoPetrovic opened this issue Oct 27, 2017 · 5 comments
Open

Comments

@SantinoPetrovic
Copy link

SantinoPetrovic commented Oct 27, 2017

Hi!

I try to use the translate extension for template select field, and it works perfectly for all subfield I've in my template fields, except for repeaters. When I try to save the other locales with values on the repeater in a record, the default locale drops its templateselect repeater values. However, if I save default locale only, it doesn't drop it.

This is the code I use:

Contenttypes.yml:

sidor: 
    name: Sidor  
    singular_name: Sida  
    singular_slug: sida  
    icon_many: fa:file  
    icon_one: fa:file
    listing_records: 4
    description: "Test"
    default_status: published
    fields:  
        locale:
            type: locale
            group: Innehåll
        title:
            type: text
            is_translateable: true
            label: Titel
            required: true
        slug:
            type: slug
            is_translateable: true
            uses: title
            label: Permalänk
        template:
            type: templateselect
            is_translateable: true
            filter: 'templateselect/sida-*'
            label: Test
        svdata:
            type: hidden
        svslug:
            type: locale_data
            index: true
        endata:
            type: hidden
        enslug:
            type: locale_data
            index: true

Theme.yml:

#/* Templatefields
#---------------------------------------------------------*/
templatefields:
    templateselect/sida-galleri.twig:
        imagelistgallery:
            type: imagelist
            label: Galleribilder
        slider:
            type: repeater
            label: Bildspel
            fields:
                repeattitle:
                    type: text
                    label: 'Titel till bilden'
                repeatteaser:
                    type: text
                    label: 'Ingresstext till bilden'
                repeatimage:
                    type: image
                    upload: bildspel
                    label: Bild            
            group: 'Galleri'


templateselect:
    templates:
         - name: 'sida med galleri'
           filename: 'templateselect/sida-galleri.twig'

Translate config file:

locales:
    sv_SE:
        label: Svenska
        slug: sv
    en_GB:
        label: English
        slug: en
routing_override: true
menu_override: true
url_generator_override: true
translate_slugs: true
use_accept_language_header: false

If I find a solution, I will reply.

Best regards,

Santino Petrovic

@SantinoPetrovic
Copy link
Author

Anyways, it looks like I were 36 commits behind and older bolt system (3.2.14), so don't mind this issue :)

@lenvanessen
Copy link

Hi Santino,

I know Svante worked on fixed for templatefields before.

I’ll check If it works with the latest versions, and If so i’ll close the issue

@matt-sonata
Copy link
Contributor

matt-sonata commented Feb 28, 2018

Also having this issue. Bolt 3.4.8, php 7.0

theme.yml:

templates/blocks/footer-links_block.twig:
    footer_links:
        type: repeater
        label: Footer Link Entries
        initial: 6
        fields: 
            footer_entry_name:
                type: text
                label: Name
            footer_entry_link:
                type: text
                label: Link This Icon Will Lead To
            footer_entry_icon:
                type: image
                label: Logo Or Icon For Entry
                attrib: alt
                extensions: [jpg, png, gif] 

contenttype.yml:


blocks:
    name: Blocks
    singular_name: Block
    fields:
        locale:
            type: locale
            group: "Block"            
        title:
            type: text
            group: "Block"
        slug:
            type: slug
            uses: [ title ]
        template:
            type: templateselect
            translatable: true
            filter: '*_block.twig'    
            postfix: <p>Please do not change this value.</p>
            readonly: true

        usdata:
            type: hidden
        usslug:
            type: locale_data
            index: true

        endata:
            type: hidden
        enslug:
            type: locale_data
            index: true 

        audata:
            type: hidden
        auslug:
            type: locale_data
            index: true  

        nzdata:
            type: hidden
        nzslug:
            type: locale_data
            index: true  

Repro steps:

In the back end:

I add data to the (templatefield) repeater field of Locale 1 & save page.
Go to (previously empty) locale 2 and all the data is copied over (loading http://page/locale 2 also shows data from locale 1).
I edit an entry in the repeaterfield of Locale 2 that has been auto populated & save page.
Change to locale 2 saves, Locale 1 is now completely blanked.

Here's my {{ dump(repeater) }} (trimmed), after the above steps have taken place.

 +"localeValues": array:20 [▼
    "id" => "3"
    "slug" => "footer-links"
    "datecreated" => "2018-02-27 13:28:10"
    "datechanged" => "2018-02-28 12:55:52"
    "datepublish" => "2018-02-27 13:28:04"
    "datedepublish" => null
    "ownerid" => "1"
    "status" => "published"
    "templatefields" => "{"footer_links":"{}"}"
    "title" => "Footer Links"
    "template" => "templates/blocks/footer-links_block.twig"
    "usdata" => "[]"
    "usslug" => "footer-links"
    "endata" => "{"templatefields":{"footer_links":[{ // Removed data for simplicity, has all data added to EN translation //]}"
    "enslug" => "footer-links"
    "audata" => "{"templatefields":{"footer_links":[{" // Removed data for simplicity, has all data added to US translation Plus change made to AU translation // }]"
    "auslug" => "footer-links"
    "nzdata" => null
    "nzslug" => ""
    "locale" => ""
  ]
}

@lenvanessen
Copy link

lenvanessen commented Feb 28, 2018 via email

@tonybelanger
Copy link

tonybelanger commented Jan 11, 2019

Hi,

This bug is still happening for me (4.1.6). I have been to resolve the issue by replacing line 237 in src/EventListener/StorageListener.php with the following condition:

if ($field === 'templatefields') {
    $record->set($field, $defaultContent->get($field)->serialize());
} else {
    $record->set($field, $defaultContent->get($field));
}

UPDATE: When I save non-default content that contains a repeater field which has a date field, I get an error when I try to edit the default content (cannot cast array to string in vendor/twig/twig/lib/Twig/Extension/Core.php line 453):

"start_date\":{\"date\":\"2019-01-15 00:00:00.000000\",\"timezone_type\":3,\"timezone\":\"EST\"}

instead of this

"start_date\":\"2019-01-01\"

I think that serialize() tries to save a Carbon object instead of the actual date value.

My temporary fix: vendor/twig/twig/lib/Twig/Extension/Core.php line 453

if (is_array($date) && isset($date['date'])) {
    $date = $date['date'];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants