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

Any module can now declare and alter entity (list) operations for entities that belong to another module by implementing hook_entity_operation() and hook_entity_operation_alter() respectively, as long as the entity type's list controller extends \Drupal\Core\Entity\EntityListController or invokes this hook itself explicitly.

Until now, declaring additional operations had to be done by implementing hook_entity_operation_alter(), which only worked for some lists and did not work if you did not want to render the operations as a dropbutton.

Adding a new operation:

/**
 * Implements hook_entity_operation().
 */
function foo_entity_operation(EntityInterface $entity) {
  $operations = array();
  if (\Drupal::currentUser->hasPermission('foo-operation') {
    $operations['foo-operation'] = array(
      'title' => t('Foo this entity'),
      'weight' => 15,
    ) + $entity->urlInfo('foo-operation');
  }

  return $operations;
}

Altering an existing operation:

/**
 * Implements hook_entity_operation_alter().
 */
function foo_entity_operation_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) {
  $uri = $entity->uri();
  $operations['translate']['title'] = t('Translate @entity_type', array(
    '@entity_type' => $entity->getEntityType()->getLabel(),
  ));
}

See Entity listing pages can be provided by a list controller for the original change notice on list controllers.

Impacts: 
Module developers