summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/user/user.module29
-rw-r--r--modules/user/user.test50
2 files changed, 79 insertions, 0 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 500875779..adfb493c1 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -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'])) {
@@ -1797,6 +1805,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().
*/
function user_admin_paths() {
@@ -1809,6 +1827,17 @@ function user_admin_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.
*
* @param $uid
diff --git a/modules/user/user.test b/modules/user/user.test
index 2cfb45671..2d54f7078 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -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.
*/