diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 3b444e7..3465313 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -946,7 +946,7 @@ function _menu_link_translate(&$item, $translate = FALSE) { // options array. For performance reasons we only invoke this hook if the link // has the 'alter' flag set in the options array. if (!empty($item['options']['alter'])) { - drupal_alter('translated_menu_link', $item, $map); + \Drupal::moduleHandler()->alter('translated_menu_link', $item); } return $map; diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php index 865878a..24bfdcb 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php @@ -19,7 +19,7 @@ class UserAccountLinksTests extends WebTestBase { * * @var array */ - public static $modules = array('menu', 'block'); + public static $modules = array('menu', 'block', 'test_page_test'); public static function getInfo() { return array( @@ -29,6 +29,12 @@ public static function getInfo() { ); } + function setUp() { + // Make test-page default. + parent::setUp(); + config('system.site')->set('page.front', 'test-page')->save(); +} + /** * Tests the secondary menu. */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index f629882..5fda5b6 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -921,14 +921,33 @@ function user_menu_breadcrumb_alter(&$active_trail, $item) { } /** - * Implements hook_menu_link_load(). - */ -function user_menu_link_load($menu_links) { +* Implements hook_translated_menu_link_alter(). +* Alter a menu link after it has been translated and before it is rendered. +* +* This hook is invoked from _menu_link_translate() after a menu link has been +* translated; i.e., after dynamic path argument placeholders (%) have been +* replaced with actual values, the user access to the link's target page has +* been checked, and the link has been localized. +* @see core/includes/menu.inc/function _menu_link_translate() +* +* It is only invoked if $item['options']['alter'] has been set to +* a non-empty value (e.g., TRUE). +* This flag should be set using hook_menu_link_presave(). +* @see /core/modules/menu_link/menu_link.api.php. +* +* Implementations of this hook are able to alter any property of the menu link. +* For example, this hook may be used to add a page-specific query string to all +* menu links, or hide a certain link by setting: +* @code +* 'hidden' => 1, +* @endcode +* +* @param $link - A menu link. +*/ +function user_translated_menu_link_alter(&$link) { // Hide the "User account" link for anonymous users. - foreach ($menu_links as $link) { - if ($link['link_path'] == 'user' && $link['module'] == 'system' && !$GLOBALS['user']->id()) { - $link['hidden'] = 1; - } + if ($link['link_path'] == 'user' && $link['module'] == 'system' && !$GLOBALS['user']->id()) { + $link['hidden'] = 1; } }