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 #2544696: Content translation metadata is only being saved when using the content translation form).

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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
mattlc’s picture

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.

exception is : "The attribute content_translation_source does not exist on the node--article resource type."