By mohit_aghera on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.1.x
Introduced in version:
10.1.0
Issue links:
Description:
MenuLinkContent entities now have full fledged operations link support like other entities.
It is now possible to leverage other alter hooks that are meant for operations links.
Examples
How to alter the title of edit link
/**
* Implements hook_entity_operation_alter().
*/
function hook_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (!$entity instanceof MenuLinkContent) {
return;
}
// Alter the title of the edit link appearing in operations menu.
$operations['edit']['title'] = t('Altered Edit Title');
}How to add a new operations link
/**
* Implements hook_entity_operation().
*/
function hook_entity_operation(EntityInterface $entity) {
if (!$entity instanceof MenuLinkContent) {
return;
}
$operations['custom_operation'] = [
'title' => t('Custom Home'),
'weight' => 20,
'url' => Url::fromRoute('<front>'),
];
return $operations;
}
Impacts:
Module developers
Site templates, recipes and distribution developers