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
- Install Drupal
- Add a view with a normal menu with a description
- Confirm the description is added to the title attribute of the menu link
- 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)
- 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
- Agree on approach
- Write a patch with tests
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 9nbOr0M.png | 297.9 KB | miraj9093 |
| #33 | 492380.33.patch | 7.17 KB | miraj9093 |
| #30 | add-test-for-rendering-the-local-task-492380-29-must-fail.patch | 1.26 KB | sutharsan |
| #29 | add-test-and-original-patch-for-rendering-the-local-task-492380-29.patch | 1.81 KB | wadmiraal |
| #29 | interdiff-492380-25-29.txt | 721 bytes | wadmiraal |
Comments
Comment #1
gpk commentedNote 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() ...
Comment #2
skizzo commentedComment #3
skizzo commentedComment #4
skizzo commentedComment #5
mlncn commentedThis 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:
... 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.
Comment #6
JuliaKM commentedI 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.
Is there a better way to test that the problem is still present?
Comment #7
JuliaKM commentedComment #8
grasmash commentedThis bug still appears to be present in Drupal 8. I directly edited node_menu() and modified node/%node/edit:
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!
Comment #9
grasmash commentedPatch 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.
Comment #10
BrockBoland commentedI confirmed that the bug still existed by adding a description to the
node/%node/editmenu item innode.module:View a node as an admin, and inspect the Edit tab: without the fix from #9, there is no
titleattribute on the link. This patch is a good start, but we will need a test case.This should check if
$link['description']is empty before setting the attributes, so we don't wind up with emptytitle=""attributes on links.Also, this should probably only set the title attribute (
$link['localized_options']['attributes']['title'] = …) in case there are other values in theattributesarray when it gets to this point.Comment #11
grasmash commented@brockboland
Good points. I'll roll another patch.
Comment #12
grasmash commentedNew patch with changes mentioned in #10
Comment #13
grasmash commentedupdating status.
Comment #14
trogels commentedNice! 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.
Comment #15
pooja.sarvaiye commentedTested the patch for programmatically created page with menu descriptions. It works. Edit node link shows the description added by patch.
Comment #16
gpk commented@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.
Comment #17
chx commentedThanks 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.
Comment #18
grasmash commented@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:
then add a menu link with a description...
then check it...
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!
Comment #19
star-szrTagging for tests.
@grasmash, please post a patch if you can :)
Comment #20
wadmiraal commentedWriting a test for this.
Comment #21
wadmiraal commentedPatch from #14 does not apply anymore, because the functions changed. Re-rolling patch.
Note: this patch was cancelled, see #24.
Comment #22
wadmiraal commentedTest for checking the description got rendered as a title.
Note: this patch should fail.
Comment #23
wadmiraal commentedEdit: see next comment.
Comment #24
wadmiraal commentedRemade 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).
Comment #25
wadmiraal commentedThis patch includes both the patches from #22 and #24.
Note: this patch should pass.
Comment #26
sutharsan commented@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.
Comment #27
sutharsan commentedNever mind #26, I now see that this the-only patch was made in #22.
Comment #28
wadmiraal commentedOk, sorry. I'm a bit of n00b in this area. This issue got a bit messy. Let me clarify what has been done.
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.
This interdiff contains all the modifications between the original patch in #14 and the patch in #25.
Comment #29
wadmiraal commentedUpdate test to use t() for the local task description.
Comment #30
sutharsan commentedAll looks good to me.
Below patch is #29 without the functional change and must fail. If it does, it is ready for RTBC.
Comment #33
miraj9093 commentedpatch rerolled.its seems patch is aquiring bigger space. need some review
Comment #34
yesct commentedtalked 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.
Comment #35
miraj9093 commentedComment #37
miraj9093 commentedHave 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.
Comment #38
danchadwick commentedI'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).
Comment #39
danchadwick commentedAlso, this issue relates to local tasks. The same change should be made to local actions.
Comment #40
pwolanin commentedThe summary is really outdated in terms of 8.x
Comment #46
manuel.adanIMHO, 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.
Comment #50
pameeela commentedComment #51
pameeela commentedUpdated IS with steps to test. Still needs input on the preferred approach.