Handlers

Last updated on
13 October 2016

Handlers were previously known as Controllers. See Change Record.
While entities represent a piece of data, handlers are responsible for acting on and with them. Handlers of an entity can be accessed through the entity_type.manager service:

Storage

The storage handler implements EntityStorageInterface and will default to ContentEntityStorageBase, a handler that implements standard methods for crud operations.

Access

The access handler implements EntityAccessControlHandlerInterface and will default to EntityAccessControlHandler

List Builder

The list builder implements EntityListBuilderInterface and will default to EntityListBuilder

View Builder

The view builder implements EntityViewBuilderInterface and will default to EntityViewBuilder

Form

The form handler implements EntityFormInterface. Since EntityForm already implements that interface, you can extend it to provide classes for such high level operations as add, edit, and delete. You would then provide user access to those operations through routing.yml files. See the Drupal Examples project configuration entity example, src/Entity/Robot.php.

Example usage:

$storage = \Drupal::entityManager()->getStorage('node');

$storage->load(1);
$storage->loadMultiple(array(1, 2, 3));
// Equaivalent to $node->save().
$storage->save($node);
$new_node = $storage->create(array('title' => 'My awesome node'));