Issue/motivation

I've faced an issue when importing translation results in fatal error Recoverable fatal error: Argument 1 passed to Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource::doSaveTranslations() must implement interface Drupal\Core\Entity\ContentEntityInterface, null given, called in /var/www/docroot/modules/contrib/tmgmt/sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php on line 427

It's pretty similar to this "Check for the existence of the delta of a field when importing translated values into it." issue but in my case it happens with a bit less complex conditions. In my case it happens when you try to import translation for node with referenced entity (paragraph) which has a multivalue field(s).

So here is the case:
1. Create node with paragraph.
2. Add two or more values into multivalue field inside of a paragraph (most likely it could be reproduced not only with paragraphs but with other referenced entities with multivalue fields).
3. Request translation.
4. Remove one value from multivalue field inside of paragraph.
5. Try to import translation.

Seems like the reason of such behavior is in ContentEntitySource::doSaveTranslations():

if (isset($property_data['#translation']['#text']) && $property_data['#translate']) {
            ...
          }
          // If the field is an embeddable reference, we assume that the
          // property is a field reference.
          elseif (isset($embeded_fields[$name])) {
            $this->doSaveTranslations($translation->get($name)->offsetGet($delta)->$property, $property_data, $target_langcode);
          }

So the problem is here $translation->get($name)->offsetGet($delta)->$property. We're trying to get a value by $delta that doesn't exist in $translation.

It worth to mention that this issue appears in our 3rd party provider. But we use tmgmt api for importing translations from files (Job::addTranslatedData()).

Possible solution

I think that possible solution is to check offset before calling ContentEntitySource::doSaveTranslations()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Loparev created an issue. See original summary.

Loparev’s picture

Issue summary: View changes
Berdir’s picture

Status: Needs review » Closed (duplicate)

Thanks for the patch. Looks like your fix is actually almost identical to #2788697: Check for the existence of the delta of a field when importing translated values into it., so I'm closing it as a duplicate of that.