public function EntityReferenceRevisions::getTarget in Entity Reference Revisions 8
Gets the referenced data.
Return value
\Drupal\Core\TypedData\TypedDataInterface|null The referenced typed data object, or NULL if the reference is unset.
Overrides EntityReference::getTarget
File
- src/
Plugin/ DataType/ EntityReferenceRevisions.php, line 74  
Class
- EntityReferenceRevisions
 - Defines an 'entity_reference_revisions' data type.
 
Namespace
Drupal\entity_reference_revisions\Plugin\DataTypeCode
public function getTarget() {
  if (!isset($this->target) && isset($this->revision_id)) {
    $storage = \Drupal::entityTypeManager()
      ->getStorage($this
      ->getTargetDefinition()
      ->getEntityTypeId());
    // By default always load the default revision, so caches get used.
    $entity = $storage
      ->load($this->id);
    if ($entity !== NULL && $entity
      ->getRevisionId() != $this->revision_id) {
      // A non-default revision is a referenced, so load this one.
      $entity = $storage
        ->loadRevision($this->revision_id);
    }
    $this->target = isset($entity) ? $entity
      ->getTypedData() : NULL;
  }
  return $this->target;
}