You are here

public function EntityTestController::listReferencingEntities in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listReferencingEntities()

List entity_test entities referencing the given entity.

Parameters

string $entity_reference_field_name: The name of the entity_reference field to use in the query.

string $referenced_entity_type: The type of the entity being referenced.

int $referenced_entity_id: The ID of the entity being referenced.

Return value

array A renderable array.

1 string reference to 'EntityTestController::listReferencingEntities'
entity_test.routing.yml in core/modules/system/tests/modules/entity_test/entity_test.routing.yml
core/modules/system/tests/modules/entity_test/entity_test.routing.yml

File

core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php, line 87
Contains \Drupal\entity_test\Controller\EntityTestController.

Class

EntityTestController
Controller routines for entity_test routes.

Namespace

Drupal\entity_test\Controller

Code

public function listReferencingEntities($entity_reference_field_name, $referenced_entity_type, $referenced_entity_id) {

  // Early return if the referenced entity does not exist (or is deleted).
  $referenced_entity = $this
    ->entityManager()
    ->getStorage($referenced_entity_type)
    ->load($referenced_entity_id);
  if ($referenced_entity === NULL) {
    return array();
  }
  $query = $this->entityQueryFactory
    ->get('entity_test')
    ->condition($entity_reference_field_name . '.target_id', $referenced_entity_id);
  $entities = $this
    ->entityManager()
    ->getStorage('entity_test')
    ->loadMultiple($query
    ->execute());
  return $this
    ->entityManager()
    ->getViewBuilder('entity_test')
    ->viewMultiple($entities, 'full');
}