You are here

protected function ContentEntitySource::findReferencedEntity in Translation Management Tool 8

Parameters

\Drupal\Core\Field\FieldItemListInterface $field:

array $field_item:

$delta:

$property:

bool $is_target_type_translatable: (optional) Whether the target entity type is translatable.

Return value

\Drupal\Core\Entity\ContentEntityInterface|null

1 call to ContentEntitySource::findReferencedEntity()
ContentEntitySource::doSaveTranslations in sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php
Saves translation data in an entity translation.

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 769

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

protected function findReferencedEntity(FieldItemListInterface $field, array $field_item, $delta, $property, $is_target_type_translatable = TRUE) {

  // If an id is provided, loop over the field item deltas until we find the
  // matching entity. In case of untranslatable target types return the
  // source target entity as it will be duplicated.
  if (isset($field_item[$property]['#id'])) {
    foreach ($field as $item_delta => $item) {
      if ($item->{$property} instanceof ContentEntityInterface) {

        /** @var ContentEntityInterface $referenced_entity */
        $referenced_entity = $item->{$property};
        if ($referenced_entity
          ->id() == $field_item[$property]['#id'] || $item_delta === $delta && !$is_target_type_translatable) {
          return $referenced_entity;
        }
      }
    }

    // @todo Support loading an entity, throw an exception or log a warning?
  }
  elseif ($field
    ->offsetExists($delta) && $field
    ->offsetGet($delta)->{$property} instanceof ContentEntityInterface) {
    return $field
      ->offsetGet($delta)->{$property};
  }
}