Frage

I currently have a simple menu_alter hook in a new module I'm building which allows simple access control for menus:

<?php 

function amh_menu_menu_alter(&$items)
{
    $items['admin/build/menu/access'] = array(
    'title' => 'Access',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('amh_menu_access_configure'),
    'access arguments' => array('administer menu'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 5,
    'file' => 'amh_menu.admin.inc',
  );
}

However, I get the following error when loading the page:

[Mon Feb 21 11:25:15 2011] [error] [client 10.2.2.106] PHP Fatal error:  require_once(): 
Failed opening required '/amh_menu.admin.inc' 
(include_path='.:/usr/share/php:/usr/share/pear') 
in /var/www/shop.dev.amh/www/includes/menu.inc on line 346, 
referer: http://shop.dev.amh/admin/build/menu

Looking at other modules which have menu and menu_alter hooks, they all refer to local module.admin.inc in places, and they don't have this problem and don't appear to specify any extra path.

Indeed - the documentation for menu hooks says that the "file path" menu item parameter is

The path to the directory containing the file specified in "file". This defaults to the path to the module implementing the hook.

How do I make this work?

War es hilfreich?

Lösung

You can explicitly set the file path to drupal_get_path('module', 'yourmodule'). That is the default, but the default is set before hook_menu_alter() is called.

The question is, why do you define a new menu item in hook_menu_alter() instead of hook_menu(). The alter hook is supposed to change existing hooks of other modules, not add new ones.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top