Failure to import paragraph translations

Created on 1 November 2022, about 2 years ago
Updated 29 January 2023, almost 2 years ago

Problem/Motivation

after applying the fix from πŸ› Translations not exported properly Closed: duplicate to properly export translations, I ran into the following error when trying to import content with translatable (asymmetric) paragraphs:

Drupal\Core\Entity\EntityStorageException: Invalid translation language (und) specified. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (regel 811 van /var/www/html/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

generated by the save() method in the following code segment:

    // Sync translations of the entity.
    if (isset($content['translations']) && $entity instanceof TranslatableInterface) {
      foreach ($content['translations'] as $langcode => $translation_content) {
        $translated_entity = !$entity->hasTranslation($langcode) ? $entity->addTranslation($langcode) : $entity->getTranslation($langcode);

        $this->importBaseValues($translated_entity, $translation_content['base_fields']);
        $this->importCustomValues($translated_entity, $translation_content['custom_fields']);

        $translated_entity->save();
      }
    }

the problem seems to be related to this core issue: https://www.drupal.org/project/drupal/issues/3226689 β†’
since the $translated_entity is created using addTranslation() method which will not set the proper content_translation_source property

Steps to reproduce

Have a site with at least 2 languages.
Create a simple content type with a paragraph reference field: make the field translatable and use the experimental asymmetric widget.
Create a content and export it with translations. Then try to import it on another site with similar configuration.

Proposed resolution

I was able to work around the issue by setting the content_translation_source property manually, before saving the translations:

$translated_entity->set('content_translation_source', $entity->language()->getId());
πŸ› Bug report
Status

Fixed

Version

1.3

Component

Code

Created by

πŸ‡·πŸ‡΄Romania reszli TΓ’rgu MureΘ™

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024