Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContentEntityBase.php

function ContentEntityBase::referencedEntities

Overrides EntityBase::referencedEntities

2 calls to ContentEntityBase::referencedEntities()
Comment::referencedEntities in core/modules/comment/src/Entity/Comment.php
Gets a list of entities referenced by this entity.
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 1305

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal