You are here

public function ContentEntityBase::referencedEntities in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()

Gets a list of entities referenced by this entity.

Return value

\Drupal\Core\Entity\EntityInterface[] An array of entities.

Overrides Entity::referencedEntities

1 call to ContentEntityBase::referencedEntities()
Comment::referencedEntities in core/modules/comment/src/Entity/Comment.php
Gets a list of entities referenced by this entity.
1 method overrides ContentEntityBase::referencedEntities()
Comment::referencedEntities in core/modules/comment/src/Entity/Comment.php
Gets a list of entities referenced by this entity.

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 1059
Contains \Drupal\Core\Entity\ContentEntityBase.

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function referencedEntities() {
  $referenced_entities = array();

  // Gather a list of referenced entities.
  foreach ($this
    ->getFields() as $field_items) {
    foreach ($field_items as $field_item) {

      // Loop over all properties of a field item.
      foreach ($field_item
        ->getProperties(TRUE) as $property) {
        if ($property instanceof EntityReference && ($entity = $property
          ->getValue())) {
          $referenced_entities[] = $entity;
        }
      }
    }
  }
  return $referenced_entities;
}