Wrong content_translation_source if source language is different from original site

Created on 20 July 2023, over 1 year ago
Updated 30 March 2024, 8 months ago

Problem/Motivation

We noticed that sync was failing with this error:

InvalidArgumentException : Invalid translation language (und) specified. dans Drupal\Core\Entity\ContentEntityBase->getTranslation() (ligne 874 de /home/mnhnweb/production/sites/multimedia-drupal9-mnhn/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php)

It seems to happen because ImportService does not set content_translation_source correctly when adding a new translation (see 🐛 Content translation metadata is only being saved when using the content translation form Needs work ).

Steps to reproduce

This happens with this setup:

  • Entity exists on site A in English and French and source language is French
  • Entity exists on site B only in English and source language is English

We synchronize from site A to site B.
The French version fetched from site A has content_translation_source to und (because on site A, the French version is not a translation, but the source version).
This seems to confuse content_translation_entity_presave() on site B: it tries to synchronize fields from und to fr which triggers the exception.

Proposed resolution

Setting content_translation_source to the correct source language from site B (so English in my example) in ImportService::getProcessedEntity() seems to fix the problem for us.
The entity will keep different source languages on both sites but it will stop triggering an exception when syncing it.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇫🇷France prudloff Lille

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

Comments & Activities

  • Issue created by @prudloff
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    42 pass
  • @prudloff opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇫🇷France mattlc

    Hi,
    Thank you for this patch.
    However it fails when content translation is not enabled in B.
    As the code is directly in "ImportService", it should control more strictly the config sync between A and B.
    I think that your code should be integrated in the language_fallback import processor and test if content translation is UP and active for current entity bundle.

Production build 0.71.5 2024