You are here

public function FieldCollectionItem::getHost in Field collection 8.3

Same name and namespace in other branches
  1. 8 src/Entity/FieldCollectionItem.php \Drupal\field_collection\Entity\FieldCollectionItem::getHost()

Returns the host entity of this field collection item.

Parameters

bool: (optional) TRUE to reset the internal cache for the host's entity type. Defaults to FALSE.

Return value

\Drupal\Core\Entity\ContentEntityInterface The host entity of this field collection item or NULL if the reference doesn't exist in the host yet.

Overrides FieldCollectionItemInterface::getHost

4 calls to FieldCollectionItem::getHost()
FieldCollectionItem::delete in src/Entity/FieldCollectionItem.php
Deletes an entity permanently.
FieldCollectionItem::deleteHostEntityReference in src/Entity/FieldCollectionItem.php
Deletes the host entity's reference of the field collection item.
FieldCollectionItem::getDelta in src/Entity/FieldCollectionItem.php
Returns the $delta of the reference to this field collection item.
FieldCollectionItem::save in src/Entity/FieldCollectionItem.php
Save the field collection item.

File

src/Entity/FieldCollectionItem.php, line 266

Class

FieldCollectionItem
Defines the field collection item entity class.

Namespace

Drupal\field_collection\Entity

Code

public function getHost($reset = FALSE) {
  $host_type = $this->host_type->value;
  $entity_info = $this
    ->entityTypeManager()
    ->getDefinition($host_type, TRUE);
  if ($id = $this
    ->getHostId()) {
    $storage = $this
      ->entityTypeManager()
      ->getStorage($host_type);
    if ($reset) {
      $storage
        ->resetCache([
        $id,
      ]);
    }
    $host_entity = $storage
      ->load($id);
    if ($entity_info
      ->isRevisionable() && ($rev_id = $this
      ->getHostRevisionId()) && $rev_id != $host_entity
      ->getRevisionId()) {
      $host_entity = $storage
        ->loadRevision($rev_id);
    }
    return $host_entity;
  }
  else {
    return NULL;
  }
}