You are here

public function EntityUsage::listReferencedEntities in Entity Usage 8.4

Same name and namespace in other branches
  1. 8 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::listReferencedEntities()
  2. 8.2 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::listReferencedEntities()

Determines referenced entities (deprecated).

This method should not be used in new integrations, and is only provided as BC-layer for existing implementations. Note however that the count returned on 2.x will be different from the count returned on 1.x, once now we track all revisions / translations independently.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A source entity.

Return value

array A nested array with usage data.The first level is keyed by the type of the target entity, the second by the referencing objects ID. The value of the second level contains the usage count, which will be summed for all revisions and translations tracked.

Overrides EntityUsageInterface::listReferencedEntities

Deprecated

in branch 2.x. Use \Drupal\entity_usage\EntityUsageInterface::listTargets() instead.

File

src/EntityUsage.php, line 388

Class

EntityUsage
Defines the entity usage base class.

Namespace

Drupal\entity_usage

Code

public function listReferencedEntities(EntityInterface $entity) {
  $result = $this
    ->listTargets($entity);
  $references = [];
  foreach ($result as $target_entity_type => $entity_record) {
    foreach ($entity_record as $entity_id => $records) {
      foreach ($records as $record) {
        if (empty($references[$target_entity_type][$entity_id])) {

          // This is the first of this entity type/id, just store the count.
          $references[$target_entity_type][$entity_id] = $record['count'];
        }
        else {

          // Sum all counts for different revisions or translations.
          $references[$target_entity_type][$entity_id] += $record['count'];
        }
      }
    }
  }
  return $references;
}