Commit 9d93bc36 authored by catch's avatar catch

Issue #1912806 by dcrocks, marthinal, jthorson, amateescu, julien, sun:...

Issue #1912806 by dcrocks, marthinal, jthorson, amateescu, julien, sun: Regression: 'User Account' displayed on front page for anonymous users.
parent 6b1b996c
......@@ -10,6 +10,36 @@
* @{
*/
/**
* 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. It is only invoked if
* $menu_link['options']['alter'] has been set to a non-empty value (e.g. TRUE).
* This flag should be set using hook_menu_link_presave().
*
* 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 \Drupal\menu_link\Entity\MenuLink $menu_link
* A menu link entity.
* @param array $map
* Associative array containing the menu $map (path parts and/or objects).
*
* @see hook_menu_link_alter()
*/
function hook_translated_menu_link_alter(\Drupal\menu_link\Entity\MenuLink &$menu_link, $map) {
if ($menu_link->href == 'devel/cache/clear') {
$menu_link->localized_options['query'] = drupal_get_destination();
}
}
/**
* Alter menu links when loaded and before they are rendered.
*
......
......@@ -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() {
);
}
public function setUp() {
parent::setUp();
// Make test-page default.
\Drupal::config('system.site')->set('page.front', 'test-page')->save();
}
/**
* Tests the secondary menu.
*/
......@@ -61,8 +67,11 @@ function testSecondaryMenu() {
$this->drupalGet('<front>');
// For a logged-out user, expect no secondary links.
$element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu'));
$this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
$tree = menu_build_tree('account');
$this->assertEqual(count($tree), 1, 'The secondary links menu contains only one menu link.');
$link = reset($tree);
$link = $link['link'];
$this->assertTrue((bool) $link->hidden, 'The menu link is hidden.');
}
/**
......
......@@ -854,14 +854,12 @@ function user_menu_breadcrumb_alter(&$active_trail, $item) {
}
/**
* Implements hook_menu_link_load().
* Implements hook_translated_menu_link_alter().
*/
function user_menu_link_load($menu_links) {
function user_translated_menu_link_alter(MenuLink &$menu_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 ($menu_link->link_path == 'user' && $menu_link->module == 'system' && \Drupal::currentUser()->isAnonymous()) {
$menu_link->hidden = 1;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment