public function EntityTestController::listReferencingEntities in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listReferencingEntities()
- 9 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()
->accessCheck(TRUE)
->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');
}