function EntityTestController::listReferencingEntities
Same name in other branches
- 9 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listReferencingEntities()
- 10 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listReferencingEntities()
- 11.x 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 35
Class
- EntityTestController
- Controller routines for entity_test routes.
Namespace
Drupal\entity_test\ControllerCode
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->entityTypeManager()
->getStorage($referenced_entity_type)
->load($referenced_entity_id);
if ($referenced_entity === NULL) {
return [];
}
$query = $this->entityTypeManager()
->getStorage('entity_test')
->getQuery()
->condition($entity_reference_field_name . '.target_id', $referenced_entity_id);
$entities = $this->entityTypeManager()
->getStorage('entity_test')
->loadMultiple($query->execute());
return $this->entityTypeManager()
->getViewBuilder('entity_test')
->viewMultiple($entities, 'full');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.