function hook_menu_link_presave

Alter the data of a menu link entity before it is created or updated.

Parameters

\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link: A menu link entity.

See also

hook_menu_link_load()

Related topics

1 function implements hook_menu_link_presave()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

user_menu_link_presave in drupal/core/modules/user/user.module
Implements hook_menu_link_presave().

File

drupal/core/modules/menu_link/menu_link.api.php, line 50
Hooks provided by the Menu link module.

Code

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;
  }
}