drupal menu_alter 在错误的位置寻找包含文件
我目前在我正在构建的新模块中有一个简单的 menu_alter 挂钩,它允许对菜单进行简单的访问控制:
<?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',
);
}
但是,加载页面时出现以下错误:
[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
查看具有 menu 和 menu_alter 挂钩的其他模块,它们都引用本地 module.admin.inc 的地方,他们没有这个问题,并且似乎没有指定任何额外的路径。
事实上 - 菜单挂钩的文档说“文件路径”菜单项参数是
包含的目录的路径 “文件”中指定的文件。这 默认为模块的路径 实现钩子。
我该如何进行这项工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将文件路径显式设置为 drupal_get_path('module', 'yourmodule')。这是默认值,但默认值是在调用 hook_menu_alter() 之前设置的。
问题是,为什么要在 hook_menu_alter() 而不是 hook_menu() 中定义新菜单项。 alter hook 应该更改其他模块的现有挂钩,而不是添加新的挂钩。
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.