You are here

protected function FieldInheritancePluginBase::getSourceEntity in Field Inheritance 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/FieldInheritance/FieldInheritancePluginBase.php \Drupal\field_inheritance\Plugin\FieldInheritance\FieldInheritancePluginBase::getSourceEntity()

Get the translated source entity.

Return value

Drupal\Core\Entity\EntityInterface|bool The translated source entity, or FALSE.

5 calls to FieldInheritancePluginBase::getSourceEntity()
FieldInheritancePluginBase::appendData in src/Plugin/FieldInheritance/FieldInheritancePluginBase.php
Retrieve appended data.
FieldInheritancePluginBase::computeValue in src/Plugin/FieldInheritance/FieldInheritancePluginBase.php
Compute the value of the field.
FieldInheritancePluginBase::fallbackData in src/Plugin/FieldInheritance/FieldInheritancePluginBase.php
Retrieve fallback data.
FieldInheritancePluginBase::inheritData in src/Plugin/FieldInheritance/FieldInheritancePluginBase.php
Retrieve inherited data.
FieldInheritancePluginBase::prependData in src/Plugin/FieldInheritance/FieldInheritancePluginBase.php
Retrieve prepended data.

File

src/Plugin/FieldInheritance/FieldInheritancePluginBase.php, line 341

Class

FieldInheritancePluginBase
Abstract class FieldInheritancePluginBase.

Namespace

Drupal\field_inheritance\Plugin\FieldInheritance

Code

protected function getSourceEntity() {
  $entity = $this->entity;
  if (empty($entity)) {
    return FALSE;
  }
  $state_key = $entity
    ->getEntityTypeId() . ':' . $entity
    ->uuid();
  $state = $this->keyValue
    ->get('field_inheritance');
  $state_values = $state
    ->get($state_key);
  if (!empty($state_values[$this->fieldInheritanceId]['entity'])) {
    if ($source = $this->entityTypeManager
      ->getStorage($this->sourceEntityType)
      ->load($state_values[$this->fieldInheritanceId]['entity'])) {
      $context['data'] = $source;
      $context += [
        'operation' => 'entity_view',
        'langcode' => $this->langCode,
      ];
      $candidates = $this->languageManager
        ->getFallbackCandidates($context);
      foreach ($candidates as $candidate) {
        if ($source
          ->hasTranslation($candidate)) {
          return $source
            ->getTranslation($candidate);
        }
      }
    }
  }
  return FALSE;
}