You are here

protected function EntityReferenceHandlerBase::loadReferencedEntityFromFieldValue in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::loadReferencedEntityFromFieldValue()
  2. 2.0.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::loadReferencedEntityFromFieldValue()

Load the referenced entity, given the $entity->field_* value.

Parameters

$value:

Return value

null|\Drupal\Core\Entity\EntityInterface

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to EntityReferenceHandlerBase::loadReferencedEntityFromFieldValue()
EntityReferenceHandlerBase::push in src/Plugin/EntityReferenceHandlerBase.php
2 methods override EntityReferenceHandlerBase::loadReferencedEntityFromFieldValue()
DefaultFieldCollectionHandler::loadReferencedEntityFromFieldValue in src/Plugin/cms_content_sync/field_handler/DefaultFieldCollectionHandler.php
Load the referenced entity, given the $entity->field_* value.
DefaultMenuLinkContentReferenceHandler::loadReferencedEntityFromFieldValue in src/Plugin/cms_content_sync/field_handler/DefaultMenuLinkContentReferenceHandler.php
Load the referenced entity, given the $entity->field_* value.

File

src/Plugin/EntityReferenceHandlerBase.php, line 466

Class

EntityReferenceHandlerBase
Providing a base implementation for any reference field type.

Namespace

Drupal\cms_content_sync\Plugin

Code

protected function loadReferencedEntityFromFieldValue($value) {
  if (empty($value['target_id'])) {
    return null;
  }
  $entityTypeManager = \Drupal::entityTypeManager();
  $reference_type = isset($value['target_type']) ? $value['target_type'] : $this
    ->getReferencedEntityTypes()[0];
  $storage = $entityTypeManager
    ->getStorage($reference_type);
  $target_id = $value['target_id'];
  return $storage
    ->load($target_id);
}