ContentEntityBase::referencedEntities

public ContentEntityBase::referencedEntities()

Gets a list of entities referenced by this entity.

Return value

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

Overrides Entity::referencedEntities

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 1061

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;
}
doc_Drupal
2016-10-29 08:57:00
Comments
Leave a Comment

Please login to continue.