Problem/Motivation

The menu item description should be added as a title attribute to the menu link. This works for normal menu links, but not for menu tabs created in views or (according to OP) menu tabs created programmatically.

Steps to reproduce

  1. Install Drupal
  2. Add a view with a normal menu with a description
  3. Confirm the description is added to the title attribute of the menu link
  4. Add a view with a menu tab link with a description (or edit an existing view with a menu tab link, e.g. the Files view)
  5. See that it does not get added as the link title

Proposed resolution

Ensure the description is added as the title attribute, or perhaps remove the description field from the menu tab options.

Remaining tasks

  1. Agree on approach
  2. Write a patch with tests
  3. Review

User interface changes

TBC

API changes

None

Data model changes

None

Release notes snippet

None

Original issue summary

If a normal menu item is given a description then this gets used as the title attribute on the menu link. However if a menu tab is given a description (programmatically) then this seems to be ignored. I'm seeing this behavior both in Garland and a custom theme, with menu tabs generated by Views (i.e. user specified) and also e.g. by pathredirect module (defined in the module code). Clearing caches doesn't seem to help.
first, install drupal 8 or try simplytest.me.and then by making the link (main navigation menu & views) check it.

Comments

gpk’s picture

Note to self: my hunch would be that http://api.drupal.org/api/function/menu_local_tasks/6 isn't ensuring that the (localized) description ends up in $item['localized_options']['title'], whereas I suspect this *is* happening for menu items in the tree generated by http://api.drupal.org/api/function/menu_tree_page_data/6, as invoked by http://api.drupal.org/api/function/menu_tree/6 and used in http://api.drupal.org/api/function/menu_tree_output/6 ... need to check the content of each $tree there compared with $item in menu_local_tasks() ...

skizzo’s picture

Version: 6.10 » 6.13
skizzo’s picture

Version: 6.13 » 6.14
skizzo’s picture

Version: 6.14 » 6.19
mlncn’s picture

Version: 6.19 » 8.x-dev
Priority: Minor » Normal
Issue tags: +Novice

This bug has remained through Drupal 7 and i believe Drupal 8, but i haven't tested the latest.

Adding this line to theme_menu_local_task() fixes it:

  $link['localized_options']['attributes'] = array('title' => $link['description']);

... as does overriding theme_menu_local_task() with a theme function that adds in that line, which is my fix for a Drupal 7 site, but moving this issue to Drupal 8 as a reminder to follow up with a patch.

Or perhaps someone can get to that before me? Tagging as novice.

JuliaKM’s picture

Assigned: Unassigned » JuliaKM

I may be misunderstanding the issue. In Drupal 7, I was able to override the menu tab title and description for the node/%node/edit tab. The description is appearing.

<?php
function menu_override_menu_alter(&$items) {
	//Makes the node/nid/edit link have the title "TESTING" and also the description "TESTING description"
	$items['node/%node/edit']['title'] = 'TESTING';
	$items['node/%node/edit']['description'] = 'TESTING description';
}?>

Is there a better way to test that the problem is still present?

JuliaKM’s picture

Assigned: JuliaKM » Unassigned
grasmash’s picture

This bug still appears to be present in Drupal 8. I directly edited node_menu() and modified node/%node/edit:

  $items['node/%node/edit'] = array(
    'title' => 'Edit',
    'description' => 'Edit this node!',
    'page callback' => 'node_page_edit',
    'page arguments' => array(1),
    'access callback' => 'node_access',
    'access arguments' => array('update', 1),
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' => 'node.pages.inc',
  );

The description attribute is not outputted in the local menu task link.

The fix from comment #5 does work. I'll roll a patch if I can't find a better way to achieve this!

grasmash’s picture

Status: Active » Needs review
StatusFileSize
new845 bytes

Patch attached.

The only change I made was to add check_plain() to the $link['description'] variable-- I don't think that it has been sanitized given that $link['title'] had not been sanitized in the same function.

BrockBoland’s picture

Status: Needs review » Needs work

I confirmed that the bug still existed by adding a description to the node/%node/edit menu item in node.module:

 'description' => 'Edit this node',

View a node as an admin, and inspect the Edit tab: without the fix from #9, there is no title attribute on the link. This patch is a good start, but we will need a test case.

+++ b/core/includes/menu.incundefined
@@ -1643,6 +1643,7 @@ function theme_menu_link(array $variables) {
   $link_text = $link['title'];
+  $link['localized_options']['attributes'] = array('title' => check_plain($link['description']));
 
   if (!empty($variables['element']['#active'])) {
     // Add text to indicate active tab for non-visual users.
-- 
1.7.5.4

This should check if $link['description'] is empty before setting the attributes, so we don't wind up with empty title="" attributes on links.

Also, this should probably only set the title attribute ($link['localized_options']['attributes']['title'] = …) in case there are other values in the attributes array when it gets to this point.

grasmash’s picture

@brockboland

Good points. I'll roll another patch.

grasmash’s picture

StatusFileSize
new875 bytes

New patch with changes mentioned in #10

grasmash’s picture

Status: Needs work » Needs review

updating status.

trogels’s picture

Nice! I tested the patch with the above procedure of adding description to '/node/%node/edit'.

I made a minor adjustment since the line exceeds 80 characters.

pooja.sarvaiye’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch for programmatically created page with menu descriptions. It works. Edit node link shows the description added by patch.

gpk’s picture

Status: Reviewed & tested by the community » Needs review

@14: I think wrapping code onto a new line with a hard end-of-line is not standard practice (comments in the code are another matter). See http://drupal.org/coding-standards#linelength

Also the added description for the Edit menu tab may be a nice way of testing this works but doesn't belong here IMO. For a start, none of the other standard menu tabs provide descriptions in this way (e.g. View, Outline, Revisions, Track..... assuming they are the same in 8.x as in previous versions).

So #12 is the patch that needs testing. Possibly it needs a proper test.

chx’s picture

Status: Needs review » Needs work

Thanks for working on this issue! As noted above, there is no need to add a line break after check_plain( and as also noted. this needs a test. The test is likely very small: please add a description to an existing local task in menu_test.module and assert its presence where appropriate. When you are doing so please keep indentation proper -- I am noting this because the current patch got it wrong in node.module -- as also noted already this change does not belong to this issue.

grasmash’s picture

@chx What would be the best way to write the test? I admit, I haven't tried my hand at writing Drupal tests yet-- shame on me.

I could modify the method addMenuLink() so that it accepts a 'desc' parameter:

function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE, $weight = '0', $desc = '')
    // View add menu link page.
    $this->drupalGet("admin/structure/menu/manage/$menu_name/add");
    $this->assertResponse(200);

    $title = '!link_' . $this->randomName(16);
    $edit = array(
      'link_path' => $link,
      'link_title' => $title,
      'description' => $desc,
      'enabled' => TRUE, // Use this to disable the menu and test.
      'expanded' => $expanded, // Setting this to true should test whether it works when we do the std_user tests.
      'parent' =>  $menu_name . ':' . $plid,
      'weight' => $weight,
    );

then add a menu link with a description...

$item1 = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name, NULL, NULL, 'description text');

then check it...

    $this->assertMenuLink($item1['mlid'], array('depth' => 1, 'has_children' => 1, 'p1' => $item1['mlid'], 'p2' => 0, 'description' => 'description text'));

Is this the right idea? Let me know if I'm off the mark. Otherwise, I'll write a patch for it and submit.

Thanks!

star-szr’s picture

Issue tags: +Needs tests

Tagging for tests.

@grasmash, please post a patch if you can :)

wadmiraal’s picture

Assigned: Unassigned » wadmiraal
Status: Needs work » Active

Writing a test for this.

wadmiraal’s picture

Status: Needs review » Active
StatusFileSize
new1017 bytes

Patch from #14 does not apply anymore, because the functions changed. Re-rolling patch.
Note: this patch was cancelled, see #24.

wadmiraal’s picture

Test for checking the description got rendered as a title.
Note: this patch should fail.

wadmiraal’s picture

Status: Active » Needs review

Edit: see next comment.

wadmiraal’s picture

Status: Active » Needs review
StatusFileSize
new557 bytes

Remade patch from #21. Patch from #14 added a description to the node module hook_menu for one of the local tasks for testing purposes. This is unnecessary. I added a local task description in menu_test.module instead (already in #22).

wadmiraal’s picture

This patch includes both the patches from #22 and #24.
Note: this patch should pass.

sutharsan’s picture

@wadmiraal, To show that the test matches to the changes in this patch, can you make a second 'test-only ' patch as mentioned in https://drupal.org/contributor-tasks/write-tests at step 13.

EDIT: Never mind, now I see that this test-only patch was made in #22.

sutharsan’s picture

Never mind #26, I now see that this the-only patch was made in #22.

wadmiraal’s picture

StatusFileSize
new1.8 KB

Ok, sorry. I'm a bit of n00b in this area. This issue got a bit messy. Let me clarify what has been done.

  1. The patch in #14 does not apply to Drupal HEAD anymore. It was re-rolled in #21.
  2. A (failing) regression test was added in #22.
  3. The original patch in #14 contained an unnecessary modification that added a 'description' to the 'node/%node/edit' local task. This was for testing purposes, but is arbitrary (as it would make the edit local task the only one with a description).
    The re-rolled patch in #21 contains the same modification.
    A new patch was made #24 that removes this addition to the 'node/%node/edit' local task.
  4. In #25, a final patch was made containing the patch from #22 (the regression test) AND the actual correction, remade in #24.

This interdiff contains all the modifications between the original patch in #14 and the patch in #25.

wadmiraal’s picture

Update test to use t() for the local task description.

sutharsan’s picture

All looks good to me.
Below patch is #29 without the functional change and must fail. If it does, it is ready for RTBC.

Status: Needs review » Needs work
Issue tags: -Novice

The last submitted patch, add-test-for-rendering-the-local-task-492380-29-must-fail.patch, failed testing.

miraj9093’s picture

Issue summary: View changes
Issue tags: +Needs Review
StatusFileSize
new7.17 KB

patch rerolled.its seems patch is aquiring bigger space. need some review

yesct’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs Review

talked to @miraj9093 in irc.
because the patch was so old, the reroll might have ended up adding back large chunks that were moved/deleted. (@miraj9093 noticed the patch size was way bigger)

before trying to manually redo the changes, we thought it might be good to try and make steps to reproduce https://drupal.org/contributor-tasks/add-steps-to-reproduce

and update the issue summary with those steps to reproduce. We might be able to do that by making a view that adds a menu item that is a local task/tab.

---
ps. to set to needs review, change the status drop down instead of adding the needs review tag (having a needs review tag is confusing, sorry that is there)
---
pps. also, unassigning @wadmiraal since it has been 5 months. ;) feel free to chime back in.

miraj9093’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 33: 492380.33.patch, failed testing.

miraj9093’s picture

Status: Needs work » Closed (fixed)
Issue tags: -Novice
StatusFileSize
new297.9 KB

Have done steps to reproduced and seems it clearly having description in the title attribute.

1.) create a link(view) and give it a name with some short description.

2.) assosiate that link(view) with menu tab .

3.) using developer option inspect that element(menu tab)

3.) you can see the description with that title attribute.

danchadwick’s picture

Status: Closed (fixed) » Needs review

I'm pretty sure the title is now being double-encoded. I have tested this in D7 and the call to check_plain is neither needed nor correct.

l() will be called, which eventually calls drupal_attributes, which runs all the attributes through check_plain (even if html=TRUE is set, as this applies only to the link's title).

The consequence of this is that a description containing a valid html entity, such as "Do Sally's work" will result in a menu tool tip with the apostrophe double-encoded.

EDIT: Note that the code proposed in #5 is correct (without the check_plain).

danchadwick’s picture

Also, this issue relates to local tasks. The same change should be made to local actions.

pwolanin’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

The summary is really outdated in terms of 8.x

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

manuel.adan’s picture

IMHO, after 4 years with no activity and 9 years from its creation, this issue should be closed as "works as designed".

It is a fact that there is no support for description in local task entries in Drupal 8 and no plans for adding it. The default class for local task items, LocalTaskDefault, lacks a property or some method to get and set a description. As a result, themes do not provide support for the requested "tittle" attribute in local tasks.

I'm currently working in a web project oriented for blind people. I'm facing a lot of accessibility issues like this one. To imagine it, just try to work with the screen switched off. In particular, for the blind, there is no perceivable difference between a regular menu item and a local task item, since the main difference is their visually representation. Such context information must be added by visually hidden information, like the title attribute in links. The solution is to avoid the use of local tasks and replace it by a set of regular menus.

The local task system is not 100% accessible, and it is not mandatory that every single piece in software have to be, but it should be indicated in documentation as well as an accessible alternative for it.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Issue summary: View changes
pameeela’s picture

Version: 8.9.x-dev » 9.3.x-dev
Issue tags: -Needs issue summary update +Bug Smash Initiative

Updated IS with steps to test. Still needs input on the preferred approach.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.