function ContentEntityBase::referencedEntities

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()
  3. 11.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()

Overrides EntityBase::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 1273

Class

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

Namespace

Drupal\Core\Entity

Code

public function referencedEntities() {
    $referenced_entities = [];
    // 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.