summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-08-18 11:11:59 (GMT)
committerwebchick2012-08-18 11:11:59 (GMT)
commit203b4e6116a9dd54c4f33a1e1e7685966e32b1bf (patch)
tree206c63e43bb1d1e131db6c88a1ac7e8fecd016fb
parent3f926260874d09109f225c26bec7fb65d97f2da0 (diff)
Issue #1197622 by lyricnz, xjm, tim.plunkett, j0rd, x2x3x2: Fixed Can't enable a disabled My account menu link.
-rw-r--r--core/modules/menu/menu.admin.inc9
-rw-r--r--core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php40
-rw-r--r--core/modules/user/user.module2
3 files changed, 48 insertions, 3 deletions
diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc
index aa7c005..fc38caa 100644
--- a/core/modules/menu/menu.admin.inc
+++ b/core/modules/menu/menu.admin.inc
@@ -104,7 +104,14 @@ function _menu_overview_tree_form($tree, $delta = 50) {
$mlid = 'mlid:' . $item['mlid'];
$form[$mlid]['#item'] = $item;
$form[$mlid]['#attributes'] = $item['hidden'] ? array('class' => array('menu-disabled')) : array('class' => array('menu-enabled'));
- $form[$mlid]['title']['#markup'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' (' . t('disabled') . ')' : '');
+ $form[$mlid]['title']['#markup'] = l($item['title'], $item['href'], $item['localized_options']);
+ if ($item['hidden']) {
+ $form[$mlid]['title']['#markup'] .= ' (' . t('disabled') . ')';
+ }
+ elseif ($item['link_path'] == 'user' && $item['module'] == 'system') {
+ $form[$mlid]['title']['#markup'] .= ' (' . t('logged in users only') . ')';
+ }
+
$form[$mlid]['hidden'] = array(
'#type' => 'checkbox',
'#title' => t('Enable @title menu link', array('@title' => $item['title'])),
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php
index 31a6c02..5ef4ba9 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php
@@ -10,9 +10,17 @@ namespace Drupal\user\Tests;
use Drupal\simpletest\WebTestBase;
/**
- * Test user-links in secondary menu.
+ * Tests user links in the secondary menu.
*/
class UserAccountLinksTests extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('menu');
+
public static function getInfo() {
return array(
'name' => 'User account links',
@@ -56,4 +64,34 @@ class UserAccountLinksTests extends WebTestBase {
$element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu'));
$this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
}
+
+ /**
+ * Tests disabling the 'My account' link.
+ */
+ function testDisabledAccountLink() {
+ // Create an admin user and log in.
+ $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
+
+ // Verify that the 'My account' link is enabled.
+ $this->drupalGet('admin/structure/menu/manage/user-menu');
+ $this->assertFieldChecked('edit-mlid2-hidden', "The 'My account' link is enabled by default.");
+
+ // Disable the 'My account' link.
+ $edit = array(
+ 'mlid:2[hidden]' => FALSE,
+ );
+ $this->drupalPost('admin/structure/menu/manage/user-menu', $edit, t('Save configuration'));
+
+ // Get the homepage.
+ $this->drupalGet('<front>');
+
+ // Verify that the 'My account' link does not appear when disabled.
+ $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
+ ':menu_id' => 'secondary-menu',
+ ':href' => 'user',
+ ':text' => 'My account',
+ ));
+ $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
+ }
+
}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 313affe..535a579 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1445,7 +1445,7 @@ function user_menu_breadcrumb_alter(&$active_trail, $item) {
*/
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()) {
+ if ($link['link_path'] == 'user' && $link['module'] == 'system' && !$GLOBALS['user']->uid) {
$link['hidden'] = 1;
}
}