Example use case (from #1115998: Revamp core and UI permissions):
I have a local task 'user/%user/relationships' and a number of local tasks below that like 'user/%user/relationships/an_id'. For those with an_id, I have a custom access callback and "'access arguments' => array('view', 1, 3),". so it should pass an_id as third argument to my access callback.
However, it doesn't do that, because it only knows about the path elements/map elements of the router item. This is because menu_get_local_tasks() passes the unchanged $map information of the parent router_item to any local tasks.
I have fixed it by appending all addditional path elements for each local tasks, patch coming up in a second.
Comments
Comment #1
berdirAnd here is the patch.
Comment #2
berdirTagging with backport tags. The code in 6.x is slightly different but the same bug exists too there.
Comment #3
BenK commentedSubscribing since I'm working on the corresponding issue on the User Relationships module.
Comment #4
chx commentedComment #5
berdirHa, the new tests actually showed that my patch didn't fully solve the issue yet.
The tests add 4 menu items now. The normal menu item menu-test/local-tasks and the three following local tasks:
menu-test/local-tasks/1
menu-test/local-tasks/2
menu-test/local-tasks/3
There is an access callback function that disallows access to the second item.
It already worked when you accessed menu-test/local-tasks. But when you access menu-test/local-tasks/3 for example, we need to use slice away the third part of the url.
The new patch is now doing that based on the given tab_parent.
Two patches, the second only contains the tests to prove that they're working.
Comment #6
berdirNote that the current approach will not work when you have multiple levels of local tasks, I'm not sure how to solve that at this point. Suggestions?
Comment #8
cpliakas commentedThis is a nasty little issue. Just ran into it at http://drupal.org/node/1404590#comment-5478056. Unfortunately I don't have any suggestions at this time on how to fix the core issue, but I might try to help if time permits.
Comment #9
berdir#5: fix_map_handling_for_local_tasks2.patch queued for re-testing.
Comment #10
kscheirer#5: fix_map_handling_for_local_tasks2.patch queued for re-testing.
Comment #11
jhedstromWow, this took quite a bit of digging to find. Currently testing the patchin #5 out on a D7 site, seems to work as advertised. Will dig into why tests are failing in 8.
Comment #12
jhedstromHere is #5 re-rolled against current 8.x. Again, the tests are included as a separate patch in order to demonstrate the failure.
Comment #14
jhedstrom#12: drupal-menu-local-tasks-1137052-12.patch queued for re-testing.
Comment #25
catchLocal tasks in Drupal 7 are no longer part of the routing system. Moving this back to 7.x