Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Gábor Hojtsy on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.0
Issue links:
Description:
The new Entity List Controllers in Drupal 8 did not allow for entity operations to be altered earlier. Now they support this via a hook_entity_operation_alter()
which gets an array of operations and allows for the list of operations to be modified or expanded. This allows for eg. adding common operations to entity listings across different entity types. See hook_entity_operation_alter() for more information on the specifics of this hook.
/**
* Alter entity operations.
*
* @param array $operations
* Operations array as returned by
* \Drupal\Core\Entity\EntityStorageControllerInterface::getOperations().
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity on which the linked operations will be performed.
*/
function translation_entity_operation_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) {
$uri = $entity->uri();
$operations['translate'] = array(
'title' => t('Translate'),
'href' => $uri['path'] . '/translate',
'weight' => 50,
);
}
See Entity listing pages can be provided by a list controller for the original change notice on list controllers.
Impacts:
Module developers