Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Entities can now provide a list controller (similar to the new form controller). Existing listings like admin/structure/taxonomy (vocabularies) and admin/structure/types (content types) can be converted to use a list controller once they have been converted to the configuration system.

Drupal\Core\Entity\EntityListController provides a rudimentary listing. The class can be overridden to provide different sorting, available operations, or even rendering. For example:


/**
 * @file
 * Contains \Drupal\my_module\Plugin\Core\Entity\MyEntity.
 */

namespace Drupal\my_module\Plugin\Core\Entity;

use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\my_module\MyEntityInterface;

/**
 * Defines a custom entity.
 *
 * @EntityType(
 *   id = "my_entity",
 *   label = @Translation("My entity"),
 *   controllers = {
 *     "storage" = "Drupal\Core\Entity\DatabaseStorageController",
 *     "list" = "Drupal\my_module\SuperCoolListController"
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label"
 *     "uuid" = "uuid"
 *   }
 * )
 */
class MyEntity extends Entity implements MyEntityInterface {
}

Note that the overriding class must implement \Drupal\Core\Entity\EntityListControllerInterface.

The path of the listing page must be declared as usual to the routing system:

my_entity_type.list:
  path: '/admin/structure/my_entity_type'
  defaults:
    _entity_list: 'my_entity_type'
  requirements:
    _permission: 'administer my_entity_type'

List controllers also provide a getOperations() method, that returns operations to be displayed in that list. The default controller adds edit and delete operations by default if the current user has update/delete permissions for the given entity. ConfigEntityListController adds enable and disable operations if the configuration entity supports it.

Although entity list controllers hardcode the list of operations, they can be altered in other modules with hook_entity_operation_alter(). See Entity list operations can now be altered for more information.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done