function ContentEntityBase::referencedEntities
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()
- 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()
- 11.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::referencedEntities()
Overrides EntityBase::referencedEntities
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 1302
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
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.