Alter the data of a menu link entity before it is created or updated.
\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link: A menu link entity.
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_menu_link_presave(\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link) {
// Make all new admin links hidden (a.k.a disabled).
if (strpos($menu_link->link_path, 'admin') === 0 && $menu_link
->isNew()) {
$menu_link->hidden = 1;
}
// Flag a link to be altered by hook_menu_link_load().
if ($menu_link->link_path == 'devel/cache/clear') {
$menu_link->options['alter'] = TRUE;
}
// Flag a menu link to be altered by hook_menu_link_load(), but only if it is
// derived from a menu router item; i.e., do not alter a custom menu link
// pointing to the same path that has been created by a user.
if ($menu_link->link_path == 'user' && $menu_link->module == 'system') {
$menu_link->options['alter'] = TRUE;
}
}