Entity reference translations are lost when default language is changed

Created on 17 October 2024, 29 days ago

Problem/Motivation

In my project I have nodes with paragraphs. When I use this service to change the default language, the translations are lost.

Steps to reproduce

I have reproduced this issue with:

- Content type with paragraphs field
- Paragraph bundles are translatable.
- Paragraph bundles contains translatable text long with format fields.
- Content has spanish as source language , and english as translation.

Code to update the language (run through drush php-script):


$node = \Drupal::entityTypeManager()->getStorage('node')->load(1234);

// Change language to english, spanish passes to be a translation.
\Drupal::service('entity_change_default_language')->update($node, 'en', TRUE, ['es']);

Proposed resolution

When the values of the entity are updated , do not save them. It can be done by dropping this line. The translation is saved anyways at the end of the update function, because when content is saved, Drupal also saves the translations.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain omarlopesino

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024