Commit c1b4e8d4 authored by webchick's avatar webchick
Browse files

#925778 follow-up by manarth, sun: Fix phantom my account link for anon users,...

#925778 follow-up by manarth, sun: Fix phantom my account link for anon users, and restore former menu access functions to prevent fatal errors in upgraded sites.
parent 3d4b1549
......@@ -1789,6 +1789,14 @@ function user_menu_site_status_alter(&$menu_site_status, $path) {
* Implements hook_menu_link_alter().
*/
function user_menu_link_alter(&$link) {
// The path 'user' must be accessible for anonymous users, but only visible
// for authenticated users. Authenticated users should see "My account", but
// anonymous users should not see it at all. Therefore, invoke
// user_translated_menu_link_alter() to conditionally hide the link.
if ($link['link_path'] == 'user' && $link['module'] == 'system') {
$link['options']['alter'] = TRUE;
}
// Force the Logout link to appear on the top-level of 'user-menu' menu by
// default (i.e., unless it has been customized).
if ($link['link_path'] == 'user/logout' && $link['module'] == 'system' && empty($link['customized'])) {
......@@ -1796,6 +1804,16 @@ function user_menu_link_alter(&$link) {
}
}
/**
* Implements hook_translated_menu_link_alter().
*/
function user_translated_menu_link_alter(&$link) {
// Hide the "User account" link for anonymous users.
if ($link['link_path'] == 'user' && $link['module'] == 'system' && user_is_anonymous()) {
$link['hidden'] = 1;
}
}
/**
* Implements hook_admin_paths().
*/
......@@ -1808,6 +1826,17 @@ function user_admin_paths() {
return $paths;
}
/**
* Returns $arg or the user ID of the current user if $arg is '%' or empty.
*
* Deprecated. Use %user_uid_optional instead.
*
* @todo D8: Remove.
*/
function user_uid_only_optional_to_arg($arg) {
return user_uid_optional_to_arg($arg);
}
/**
* Load either a specified or the current user account.
*
......
......@@ -1227,6 +1227,56 @@ class UserAutocompleteTestCase extends DrupalWebTestCase {
}
}
/**
* Test user-links in secondary menu.
*/
class UserAccountLinksUnitTests extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User account links',
'description' => 'Test user-account links.',
'group' => 'User'
);
}
/**
* Test the user login block.
*/
function testSecondaryMenu() {
// Create a regular user.
$user = $this->drupalCreateUser(array());
// Log in and get the homepage.
$this->drupalLogin($user);
$this->drupalGet('<front>');
// For a logged-in user, expect the secondary menu to have links for "My
// account" and "Log out".
$link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
':menu_id' => 'secondary-menu-links',
':href' => 'user',
':text' => 'My account',
));
$this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
$link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
':menu_id' => 'secondary-menu-links',
':href' => 'user/logout',
':text' => 'Log out',
));
$this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
// Log out and get the homepage.
$this->drupalLogout();
$this->drupalGet('<front>');
// For a logged-out user, expect no secondary links.
$element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu-links'));
$this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
}
}
/**
* Test user blocks.
*/
......
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