An active li.leaf item in Drupal's menus behaves like a collapsible menu item li.collapsed and gets expanded li.expanded. This means its not displayed with a bullet but with an arrow (see screenshot).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

derjochenmeyer’s picture

Status: Active » Needs review
FileSize
314 bytes

Here is a patch that solves it. Don't know if there is a better way to do this.

derjochenmeyer’s picture

Priority: Normal » Critical

Maring this a critical since there is no way to theme leaf items as bullets without the right CSS class.

derjochenmeyer’s picture

Better screenshot.

Patch explanation: $data['below'] is not empty for some menu items even if they do not have children within the displayed menu. So its not enough to check if $data['below'] is set. Example: Menu item "Modules" has the tabs in $data['below'].

derjochenmeyer’s picture

FileSize
356.97 KB
sun’s picture

Priority: Critical » Normal
Status: Needs review » Needs work

Not critical. Please read and understand Priority levels of Issues, thanks.

+++ includes/menu.inc
@@ -915,7 +915,7 @@
+    if ($data['below']  && $data['link']['has_children']) {

Duplicate space here.

Also, can we flip the conditions, please? The second is the primary, actually.

Powered by Dreditor.

derjochenmeyer’s picture

Status: Needs work » Needs review
FileSize
313 bytes

New patch with #5 suggestions.

sun’s picture

At first, I wasn't sure whether this really needs to be fixed in menu_tree_output() or not rather in one of the tree builder functions - but changing those would potentially break other use-cases.

To get this in, we want to put a short comment before this condition to clarify that 'below' may contain local tasks, which are not output in regular menu link trees.

sun’s picture

Furthermore, I'd also like to see tests to ensure we don't break this logic/functionality again in the future.

derjochenmeyer’s picture

Status: Needs work » Needs review
FileSize
2.07 KB

This is actually a duplicate of #621758: Menu items erroneously get 'expanded' class.

This issue has also tests written by mooffie which slightly modified work here.

New patch includes suggenstions #7 and #8

derjochenmeyer’s picture

Who is wrong: the patch or the bot?

Status: Needs review » Needs work

The last submitted patch, menu_tree_output_with tests.patch, failed testing.

derjochenmeyer’s picture

#9: menu_tree_output_with tests.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, menu_tree_output_with tests.patch, failed testing.

derjochenmeyer’s picture

Status: Needs review » Needs work
FileSize
2.07 KB

Bot doesn't like spaces in patch name?

derjochenmeyer’s picture

Status: Needs work » Needs review
sun’s picture

+++ includes/menu.inc
@@ -915,7 +915,9 @@
     // Set a class if the link has children.
-    if ($data['below']) {
+    // Since $data['below'] may contain local tasks,
+    // only set 'expanded' class if the link also has children.
+    if ($data['link']['has_children'] && $data['below']) {

1) The new comment wraps too early.

2) We can combine/rephrase the old with the new comment.

+++ modules/simpletest/tests/menu.test
@@ -390,6 +390,35 @@
 
+class MenuCSSTestCase extends DrupalWebTestCase {
...
+
+  function testParentIsLeaf() {

Missing class/function docblocks.

+++ modules/simpletest/tests/menu.test
@@ -390,6 +390,35 @@
+  function get_li($text) {
+    $elements = $this->xpath("//ul[@class='menu']/li[a[text()='$text']]");
+    return $elements ? $elements[0] : NULL;

Do we really need this helper function?

+++ modules/simpletest/tests/menu_test.module
@@ -172,7 +172,19 @@
+  ¶

Trailing white-space here.

+++ modules/simpletest/tests/menu_test.module
@@ -172,7 +172,19 @@
+  $items['menu-test/css/parent'] = array(
+    'title' => 'Test CSS parent #1',
...
+  $items['menu-test/css/parent/child-link-not-shown-because-callback'] = array(
+    'title' => 'Test router item',

1) That second path looks weird.

2) The menu item titles should summarize what's being tested.

+++ modules/simpletest/tests/menu_test.module
@@ -172,7 +172,19 @@
+    'type' => MENU_CALLBACK,

Shouldn't we test local tasks?

107 critical left. Go review some!

derjochenmeyer’s picture

Status: Needs work » Needs review
FileSize
3.03 KB

Thanks for reviewing the patch.

New patch includes suggestions #16.

derjochenmeyer’s picture

Any ideas?

cwgordon7’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies with a bit of offset, and works to fix this problem, and the code looks good, so this is rtbc. Nice work!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

andypost’s picture

Status: Fixed » Reviewed & tested by the community

Commit http://drupal.org/cvs?commit=395108 missed hunks with tests

cwgordon7’s picture

Also, for some reason, this patch does not appear working for paths like admin/structure/types. Not sure if that's a side effect of not having the whole thing committed or if it's just a fault of the patch.

andypost’s picture

FileSize
4.55 KB

Confirm that admin/structure/block and admin/structure/types are displayed like holding children

derjochenmeyer’s picture

Status: Reviewed & tested by the community » Needs work

At the time this patch was written $data['below'] was empty for links without children in the current menu. Some other modification apparently changed this.

I dont see any possibility to solve this with the current approach, because we cannot tell from looking at $data anymore whether a link has children in the current menu, or if these children are (e.g.) "action-links" (like "Add content type" below "Content types").

Any ideas where to start from? Where is the $data array beeing built?

sun’s picture

Status: Needs work » Reviewed & tested by the community

I'd recommend to complete the commit first, because that work is valuable on its own.

derjochenmeyer’s picture

Can i contribute to making this commit work? If so, how?

cwgordon7’s picture

I do not think we should commit this test until we figure out why it is not catching the bug.

sun’s picture

Status: Reviewed & tested by the community » Needs work

hm, true, too.

derjochenmeyer’s picture

Any ideas where to start from?

gooddesignusa’s picture

I just ran into this issue and posted here first http://drupal.org/node/955378 (Menu items - "Has children" flag is not reset on menu reordering). Tried that patch and it didn't seem to help. Seems like this isn't the only thread of this issue. Going to try this one as well.

edit: sorry didn't realize this was for D7

JustMagicMaria’s picture

Still running into this in 7.7.

andypost’s picture

Issue summary: View changes
Issue tags: +Needs reroll

do we have the issue in d8?

  • Dries committed 3fd692b on 8.3.x
    - Patch #767478 by derjochenmeyer: menu li.leaf items get expanded (li....

  • Dries committed 3fd692b on 8.3.x
    - Patch #767478 by derjochenmeyer: menu li.leaf items get expanded (li....

  • Dries committed 3fd692b on 8.4.x
    - Patch #767478 by derjochenmeyer: menu li.leaf items get expanded (li....

  • Dries committed 3fd692b on 8.4.x
    - Patch #767478 by derjochenmeyer: menu li.leaf items get expanded (li....
vijaycs85’s picture

Do we still need this issue? Seems committed to D8 7 years back.

  • Dries committed 3fd692b on 9.1.x
    - Patch #767478 by derjochenmeyer: menu li.leaf items get expanded (li....