core icon indicating copy to clipboard operation
core copied to clipboard

Disappearing content in localized collections/sets

Open evertalbers opened this issue 2 years ago • 8 comments

Download this Bolt instance with only the affected contenttype to reproduce the bug: Wetransfer

In a localized Bolt 5.0.2 with

pages:
    name: Pages
    singular_name: Page
    fields:
(...)
        contentblocks:
            type: collection
            label: Content Blocks
            group: Extra Content Blocks
            localize: true
            fields:
                partnerlistitem:
                    label: Partner list item
                    icon: "fa-coffee"
                    type: set
                    localize: true
                    fields: 
                        partnertitle: 
                            type: text
                            label: "Partner title"
                            postfix: "<h4>Only shown in the backend to keep things orderly</h4>"
                        partnerlogo:
                            type: image
                            upload: "logos"
                            # localize: true
                        partnertext: 
                            type: redactor
                            localize: true

When I fill in a second or third partnerlistitem, content in the preceeding partnerlistitem is deleted. I cannot put my finger on what gets deleted when, but I think that at least partnerlogo fields in the existing partnerlistitems are deleted/emptied whenever a new partnerlistitem is added - even before you add content to the new item.

In this usecase, ideally the same logo would be shown for all languages, so you don't have to fill that in twice. As you can see I tried some variations with the places where localize: true is applied, I don't think I saw any difference.

As mentioned in line 1, you can use this zipped Bolt instance (or set up a fresh one using its config files, and the theme directory) to reproduce the bug Wetransfer.

Start with an empty page and (in the #extra-content-blocks tab) add 2 or 3 partnerlistitems, saving in one or both languages and refreshing at the frontend after adding each new item. You should see some of your previously entered content disappear.

When trying this out, please note that partnertitle is not supposed to be shown in the frontend, only the partnertext.

evertalbers avatar Sep 22 '21 12:09 evertalbers

I can confirm that something is not working as intended, i'm having the same problem with my Bolt 5.0.2 project. It happens when i have a collection with a set where some fields are localized, the specific part of the contenttype:

    highlights:
        type: collection
        label: Highlights
        group: Highlights
        fields:            
          contentset:
              type: set
              label: Highlight
              fields:
                  highlight_text:
                      type: text
                      label: Naam  
                      localize: true                  
                  highlight_image:
                      label: Icoon (voorkeur een SVG bestand)
                      type: image
                      extensions: [ gif, jpg, png, svg ]
                      upload: icons

Steps to reproduce the problem:

  • Add, for example 4 sets in the default locale (let's say NL). Fill in the text fields and upload the images > save
  • Switch to another locale (let's say EN) and translate the text fields. The images are not shown because they are not localized > save
  • Everything is working so far, when switching the locale on the front-end the images are shown in both languages
  • Now in Bolt switch back to the NL locale and add a 5th set. Fill in the text and the image > save
  • Switch to the EN locale, and add the text to the 5th set > save
  • Switch back to the NL locale and all the images in the sets are gone

Maybe the problem in this case is that the image field is not localized, so the image fields are filled in in the NL locale but when switching to the EN locale those fields are empty. Perhaps when saving them in the EN locale it saves the images as empty for all locales?

I hope this helps with pinpointing the problem.

Edit: After re-adding the images on the NL locale > save > everything is working again until editing the sets on another locale.

SanderOnline avatar Sep 23 '21 09:09 SanderOnline

Looking at this, I can see that there may be some weirdness going on here. The collections/sets are intended to be either fully localized or fully non-localized. I can't picture how a part of a set would be localized, but the other part would not 🤷‍♂️

And, given that, I think the "safest" way is to put them all as localized (or at least the top-level item, either the collection or the set depending on what it is).

I-Valchev avatar Oct 25 '21 12:10 I-Valchev

Fair enough, it does indeed work as intended if all the fields in the set are localized. In my specific use case there wouldn't be a need to "translate" the image field since the same image is used regardless of the locale.

But that was an assumption from my side, thanks for clearing it up :)

SanderOnline avatar Oct 25 '21 13:10 SanderOnline

No worries! I can see how that would be useful, yes.

I-Valchev avatar Oct 25 '21 13:10 I-Valchev

Same thing here, with the non-translated images. I can live without, but I would have to test if (in my example)

        contentblocks:
            type: collection
            label: Content Blocks
            group: Extra Content Blocks
            localize: true

and omitting all other "localizes" falling under contentblocks will work well.

evertalbers avatar Nov 01 '21 19:11 evertalbers

hey @evertalbers , @mcdennem just bumped into this today and it seems to break the localization. Each field inside a collection should be localized, or it will only be available in the default locale.

I-Valchev avatar Nov 04 '21 12:11 I-Valchev

Hi @I-Valchev finally had the time to try this out. Translating all fields seems to work indeed, so that's some progress. I used the field defs. below:

        contentblocks:
            type: collection
            label: Content Blocks
            group: Extra Content Blocks
            localize: true
            fields:
                partnerlistitem:
                    label: Partner list item
                    icon: "fa-coffee"
                    type: set
                    localize: true
                    fields: 
                        partnertitle: 
                            type: text
                            label: "Partner title"
                            postfix: "<h4>Only shown in the backend to keep things orderly</h4>"
                            localize: true
                        partnerlogo:
                            type: image
                            upload: "logos"
                            localize: true
                        partnertext: 
                            type: redactor
                            localize: true

So in my case there seem to be 2 options:

  1. Localize all items nested within a collection like here, so an editor will have to fill in all fields including the logo twice. Not ideal, but once you know it you can work with it.

If this is the way to go for multilocale collections I suggest making an addition to the docs.

  1. Alternatively, I could make a separate partners viewless block contenttype (multi-locale text and single-locale partnerlogo fields), and use a single-locale collection with "Populate-values-from-a-ContentType - selects" on the visible contenttype that link to the desired records.

Less work for the editor but also less intuitive.

evertalbers avatar Nov 15 '21 20:11 evertalbers

For me even if I localize all nested items it is not working. If I change something in one locale, all of the data in other is deleted.

But not everywhere. If I have that on my homepage, then translations are disappearing, and if I create viewless contenttype with translatable collection, it is OK ?!

matesko avatar Mar 18 '22 10:03 matesko