You are here

public function EntityUsageInterface::listSources in Entity Usage 8.2

Same name and namespace in other branches
  1. 8.4 src/EntityUsageInterface.php \Drupal\entity_usage\EntityUsageInterface::listSources()
  2. 8.3 src/EntityUsageInterface.php \Drupal\entity_usage\EntityUsageInterface::listSources()

Provide a list of all referencing source entities for a target entity.

Examples:

  • Return example 1:

[ 'node' => [ 123 => [ 'source_langcode' => 'en', 'source_vid' => '128', 'method' => 'entity_reference', 'field_name' => 'field_related_items', 'count' => 1, ], 124 => [ 'source_langcode' => 'en', 'source_vid' => '129', 'method' => 'entity_reference', 'field_name' => 'Related items', 'count' => 1, ], ], 'user' => [ 2 => [ 'source_langcode' => 'en', 'source_vid' => '2', 'method' => 'entity_reference', 'field_name' => 'field_author', 'count' => 1, ], ], ]

  • Return example 2:

[ 'entity_reference' => [ 'node' => [...], 'user' => [...], ] ]

Parameters

\Drupal\Core\Entity\EntityInterface $target_entity: A target entity.

bool $nest_results: (optional) Whether the results should be returned in a nested structure. Defaults to TRUE.

Return value

array A nested array with usage data. The first level is keyed by the type of the source entities, the second by the source id. The value of the second level contains all other information like the method used by the source to reference the target, the field name and the source language code. If $nest_results is FALSE, the returned array will be an indexed array where values are arrays containing all DB columns for the records.

1 method overrides EntityUsageInterface::listSources()
EntityUsage::listSources in src/EntityUsage.php
Provide a list of all referencing source entities for a target entity.

File

src/EntityUsageInterface.php, line 152

Class

EntityUsageInterface
Entity usage interface.

Namespace

Drupal\entity_usage

Code

public function listSources(EntityInterface $target_entity, $nest_results = TRUE);