I'm trying to update a single node with multiple languages, but I've found that only the lowest language (on the content page from top to bottom) is updated.

Is what I am trying to do a supported feature?

- Drupal core 8.7.2.
- Using Workbench Moderation

Thank you.

Comments

supertony created an issue. See original summary.

el1_1el’s picture

Category: Bug report » Feature request
Status: Active » Needs work

looks like you should be able to change the node language - https://www.drupal.org/node/2993847 but i dont think ive ever tested on a node with multiple languages. ill try to set something up and make a fix when i get a chance. Patches always welcome also

supertony’s picture

Thank you @el1_1el. Sorry, I'm not trying to update the language of the node, but rather a simple text field.

For example, I have a node and it has translations for English and Japanese. In this content type, there's a text field 'Fun phrase', the English translation has the value 'Turtles' and the Japanese value is 'Cakes'. I now want to change the value of both of these fields to 'Muffins'.

Steps:
1. Open the /admin/content page
2. Select both translations, have 'Bulk Update Content Fields' selected in Action, and click 'Apply to selected items' button. For this example, assume that the Japanese translation is lower on the content page.
3. Select the 'Fun phrase' field and click the 'Next' button
4. Enter value 'Muffins' into the field and click the 'Next' button
5. Click the 'Updated Fields' button

I'm now redirected to the Content page with the confirmation:

All fields were updated successfully
One field processed on One entity

Expected result:
The Fun phrase field has the value 'Muffins' for both English and Japanese translations.

Actual result:
The Fun phrase field has the value 'Muffins' for only the Japanese translation, while the English translation remains 'Turtles'.

I'm looking at the code now to see what could be causing this. Thank you again.

jlatorre’s picture

Got the same issue and the same need :)

jlatorre’s picture

StatusFileSize
new1.82 KB

Here is a first try on that

el1_1el’s picture

Version: 8.x-2.0-alpha3 » 8.x-2.x-dev
StatusFileSize
new3.76 KB

Here's a second try expanding on that against 9x-beta1, but it still only updates the last translation selected even though it seems like it shouldnt based on https://drupal.stackexchange.com/questions/218833/set-translated-field

I noticed when checking the field arrays that they came out like

[field_name] => Array(
  [x-default] => Array(
    [0] => Array(
      [value] => test1
    )
  )
  [es] => Array(
    [0] => Array(
      [value] => test1
    )
  )
  [fr] => Array(
    [0] => Array(
      [value] => test1
    )
  )
)

but when i tried updating them using

$field_value[$langcode][0]['value'] = 'test1';

instead of

$field_value[0]['value'] = 'test1';

that just updated nothing at all.

Wondering if there is a core bug between bulk updating and the "shallow clones" of translated entities? maybe someone else knows more..

jlatorre’s picture

StatusFileSize
new2.4 KB

Ok I found where the issue is, I've got a patch to fix it BUT it's not the most optimized way to do it.

In fact when you choose your different translations, let's say 10 langcodes. You put them into the batch as entities but it also sets the value field of all translations with it. So in fact you have 10 times the same entities and values.

When you update your first entity, it really updates the entity. When you get the second entity from the queue, in fact you don't have the good version of your entity, when you will update this "langcode" version, you will also override the previous one with a bad value because the field value in the queue is not good.

To avoid that, I reload the latest version of the entity to be sure to get the very last version of my entity(and its tranlsations). That is not perfect but it works for now.
IMHO we should only send one entity and a table of langcode to update.

What do you think?

el1_1el’s picture

Status: Needs work » Needs review

Hmm. Well I'm inclined to commit #7, which worked as expected btw, even though it could be optimized better.

Since its going through a bulk update, and each selected "entity" is processed one by one, it makes sense to me to treat each translation as a separate entity even if that entity is a "shallow clone". The translations are also listed in the admin/content view as separate entities, so I'm personally ok loading and processing them as such, even if they arent really separate at all under the hood.

I'm also a bit concerned if we rewrite the process to deal with the shallow clones as a single entity, it might affect things like paragraphs, which I've found tricky to handle when they get nested a level or two.

I'll think it over, maybe test a bit more in a more complex scenario, and set for review. Maybe @supertony could try it out and see how it works for him in a real environment also.

jlatorre’s picture

Just a follow up about this feature, we've been using the patch for 7 months now and no bug have been reported so far by our clients

  • jlatorre authored b75f099 on 8.x-2.x
    Issue #3121744 by jlatorre, el1_1el: Unable to update multiple languages...
el1_1el’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.