function vocabindex_menu()

{

	$items['admin/content/taxonomy/vocabindex']=array(

		'title'=>'Vocabulary index pages',

		'access arguments'=>'manage vocabulary index pages',

		'page callback'=>'drupal_get_form',

		'page arguments'=>'vocabindex_form_admin',

	);

The menu item is nowhere to be seen in the menu (using D6 beta 3). I've read the Handbooks a few times, checked hook_menu() in other modules, but so far I haven't found the bug in this. I've also emptied the menu cache, but that wouldn't help either. It's a clean D6 beta 3 install by the way.

Comments

xano’s picture

Somehow I've got the same issue with the Drupal 5 version of the code: (Of course using Drupal 5.3)

function vocabindex_menu()
{
	$items=array();

	if($may_cache)
	{
		$items[]=array(
			'path'=>'admin/content/vocabindex',
			'title'=>t('Vocabulary index pages'),
			'access'=>user_access('manage vocabulary index pages'),
			'callback'=>'drupal_get_form',
			'callback arguments'=>'vocabindex_form_admin',
		);
xano’s picture

The D5 problem is solved. I had forgotten to set $may_cache as a parameter for vocabindex_menu().

xano’s picture

I now know why it doesn't work with D6... Hook_menu() is only called when modules are enabled and not with every page load. Understandable for most cases, but not when it's your module's purpose to dynamically add new (custom) menu paths (Vocabulary Index).

[edit]
Does anyone have an idea on how to create dynamical menu callbacks for Drupal 6? For Drupal 5 I've done this by creating the items in hook_menu() when it was being called with $may_cache=FALSE, but that won't work in D6 anymore. As the hook is only called when modules are enabled I need to find another way to register callbacks linked to paths/aliases. The Vocabindex module allows users to dynamically create index pages for their vocabularies. For every page the module registers a new callback in hook_menu().

Would anyone have creative solution for this problem?

Just realized I made an error in the topic's title... :-P
[/edit]

xano’s picture

Just ignore that part about hook_menu(). I found a workaround already: Simply call menu_rebuild() as soon as there are some new menu items to be generated.

Another question:

	$items['admin/content/vocabindex']=array(
		'title'=>'Vocabulary index pages',
		'access arguments'=>'manage vocabulary index pages',
		'page callback'=>'drupal_get_form',
		'page arguments'=>array('vocabindex_form_admin'),
	);

I keep getting two or three of the following errors on some pages:

warning: Invalid argument supplied for foreach() in /Users/bart/htdocs/vocabindex D6 beta3/includes/menu.inc on line 258.

These errors only appear when the page callback of the above menu item is defined. I've checked and checked it against existing items and against the Handbooks about the D6 menu system, but I can't seem to find what's going wrong. Line 258 in menu.inc is the foreach-statement of menu_unserialize().

Never mind this post either. Access arguments have to be given in array form as well and that caused the errors. It works like a charm now :-)