function EntityTestController::listEntitiesEmpty

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listEntitiesEmpty()
  2. 10 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listEntitiesEmpty()
  3. 11.x core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php \Drupal\entity_test\Controller\EntityTestController::listEntitiesEmpty()

Empty list of entities of the given entity type.

Empty because no entities match the query. That may seem contrived, but it is an excellent way for testing whether an entity's list cache tags are working as expected.

Parameters

string $entity_type_id: The type of the entity being listed.

Return value

array A renderable array.

1 string reference to 'EntityTestController::listEntitiesEmpty'
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 112

Class

EntityTestController
Controller routines for entity_test routes.

Namespace

Drupal\entity_test\Controller

Code

public function listEntitiesEmpty($entity_type_id) {
    $entity_type_definition = $this->entityTypeManager()
        ->getDefinition($entity_type_id);
    return [
        '#theme' => 'item_list',
        '#items' => [],
        '#cache' => [
            'contexts' => $entity_type_definition->getListCacheContexts(),
            'tags' => $entity_type_definition->getListCacheTags(),
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.