~ 2 min read
Drupal Commons menu items adjustments
With commons you mostly feel like you’re always eating a mixed salad. You get a lot of Acquia’s custom features and contributed modules, which all of it builds up a specific distribution type.
Salads lose their appeal when you need to dig in and seek for a specific item, which was the case in a recent fiddling with it. Commons provides a ‘bookmarks’ link in the user’s Profile area underneath the user’s avatar, along with a bunch of other links and we needed a way to pull it into the tabbed links menu. One would wonder how to approach that?
Just by looking at the existing menu items, it’s easy to spot that they are all part of the same hierarchy and the menu system. Assuming that the menu items were done sanely, meaning no one at Acquia hard coded these links or used a custom menu hook, then they were probably declared in hook_menu()
. Where exactly is another question and while you may choose to seek this out it doesn’t really matter. Lucky for us Drupal declares a hook_menu_alter()
, which if you implement in the lowest priority module (read: highest numeric value for module’s weight in the system table) then you can easily throw in there a debug break point that looks at the $items
of the menu and locate that particular entry.
Doing that, yields the following (more or less):
[user/%views_arg/bookmarks] => Array
(
[page callback] => views_page
[page arguments] => Array
(
[0] => flag_bookmarks_tab
[1] => page
[2] => 1
)
[access callback] => og_features_menu_access_callback
[access arguments] => Array
(
[0] => views_access
[1] => views_page
[2] => Array
(
[0] => flag_bookmarks_tab
[1] => page
[2] => 1
)
[3] => views
[4] => user/%views_arg/bookmarks
[5] => Array
(
[0] => views_check_roles
[1] => Array
(
[0] => Array
(
[2] => 2
)
)
)
)
[load arguments] => Array
(
[0] => flag_bookmarks_tab
[1] => page
[2] => %index
)
[title] => Bookmarks
As suspected, the bookmarks menu entry is simply not configured as a local task for the tabbed menu.
To elegantly customize this you can create such low priority custom module to implement hook_menu_alter(&$items)
and alter the menu item type, such as:
$items['user/%views_arg/bookmarks']['type'] = MENU_LOCAL_TASK;
Clear the cache to test and confirm.