menu suggested items do not show in menu
beginner - July 16, 2008 - 02:43
| Project: | Tagadelic |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
in hook_menu():
<?php
$items['tagadelic/chunk/%tagadelic_vocs'] = array(
'title' => 'Tags',
'page callback' => 'tagadelic_page_chunk',
'page arguments' => array(2),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
?>however, when visiting admin/build/menu-customize/navigation those suggested items do not show.
I am not sure how this is supposed to be done in D6.

#1
For comparison purposes, this is how it was done in D5:
<?phpforeach (taxonomy_get_vocabularies($type = NULL) as $vocabulary) {
$items[] = array(
'title' => $vocabulary->name,
'path' => "tagadelic/chunk/$vocabulary->vid",
'callback' => 'tagadelic_page_chunk',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
}
?>
#2
I had the same problem with directory.module.
The solution is to completely restore most of the D5 code which, in this case, is completely valid for D6.
Don't use the wildcard loader.
Here is the valid D6 code for directory.module:
<?php$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies AS $vid => $vocabulary) {
$items['directory/vocabulary/' . $vocabulary->vid] = array(
'title' => t('Directory for !vocabulary-name', array('!vocabulary-name' => $vocabulary->name)),
'page callback' => 'directory_vocabulary_page',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
}
?>
#3
Did you actually create a tagadelic_vocs_load() function? The menu system kinda needs that if you're going to declare a menu hook that way. Although you probably want vocabulary_load() instead (which may or may not exist yet; not sure off hand).
A foreach loop inside a D6 menu handler is 99% of the time the WRONG way to do it.
#4
I noticed this bug with my own module (directory.module). I knew that tagadelic has a similar menu structure and that's why I checked it out.
I was using core taxonomy_vocabulary_load() function (used with the wildcard). The code worked fine as a callback. The problem is that there is no menu item ready to be enabled, like it is supposed to do.
This is the code I had just after upgrading to D6:
<?php$items['directory/vocabulary/%taxonomy_vocabulary'] = array(
'title callback' => 'directory_vocabulary_title',
'title arguments' => array(2),
'page callback' => 'directory_vocabulary_page',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
?>
As I said, it worked nice as a MENU_CALLBACK, but did not fulfill its function as MENU_SUGGESTED_ITEM.
The HEAD version of directory.module uses the code in #2, which works as intended.
So, if the foreach loop is wrong, how do I get MENU_SUGGESTED_ITEM without it?
tagadelic has exactly the same problem.
#5
subscribing
#6
Here is the official way to fix this particular bug.
Thanks to karoly for the feedback.
#7
Sorry but I didn't quite get what to do with MENU_SUGGESTED_ITEM and a wildcard loader here.
#8
Interesting. I did not test tagadelic on 6 myself, because I havo no 6 sites yet. It may have skipped past the people who reviewed the upgrades, though.
Lets solve this fast!
#9
Here is the patch.
It enabled menu items like in D5, but using menu_link_maintain() function.
Not sure it it a good solution so the menu item enabled by default.
But menu_link_maintain() does not include a mechanism to enable/disable a link.
#10
oops, forgot to change status.
#11
I am not very enthusiastic about the solution with menu_link_maintain(). AFAIK we should be able to fix this within the hook_menu very simple.