drupal 7 hook_menu() 不工作
我正在尝试向“主页”>“管理”>“配置”页面添加一个部分,然后打开一个带有 2 个选项卡(create_team 和 create_game)的新表单。
我的代码(不起作用):
function guild_management_core_menu()
{
$items['admin/config/guild_management_core/create_game'] = array
(
'title' => 'Create Game',
'description' => 'Create Game',
'page callback' => 'drupal_get_form',
'page arguments' => array('guild_management_core_create_game'),
'access arguments' => array('access administration pages'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/config/guild_management_core/create_team'] = array
(
'title' => 'Create Team',
'description' => 'Create Team',
'page callback' => 'drupal_get_form',
'page arguments' => array('guild_management_core_create_team'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
return $items;
}
我尝试了下面的链接,但它们也不起作用: drupal--hook_menu 管理菜单模块中的 Drupal hook_menu
我还禁用了该模块并再次启用它,然后我清除了缓存,但仍然没有结果。
编辑: 这有效:
$items['admin/config/annotate'] = array(
'title' => 'Guild Management',
'description' => 'Guild Management',
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
当我用“admin/config/guild_management_core”替换“admin/config/annotate”时,它再次出错......
I am trying to add a section to the Home>Administration>Configuration page which then opens a new form with 2 tabs (create_team and create_game).
My code (which does not work):
function guild_management_core_menu()
{
$items['admin/config/guild_management_core/create_game'] = array
(
'title' => 'Create Game',
'description' => 'Create Game',
'page callback' => 'drupal_get_form',
'page arguments' => array('guild_management_core_create_game'),
'access arguments' => array('access administration pages'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/config/guild_management_core/create_team'] = array
(
'title' => 'Create Team',
'description' => 'Create Team',
'page callback' => 'drupal_get_form',
'page arguments' => array('guild_management_core_create_team'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
return $items;
}
I tried the links below but they don't work either:
drupal--hook_menu
Drupal hook_menu from module for admin menu
I also disabled the module and enabled it again and then I cleared the cache but still no results.
EDIT:
This works:
$items['admin/config/annotate'] = array(
'title' => 'Guild Management',
'description' => 'Guild Management',
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
When I replace "admin/config/annotate" with "admin/config/guild_management_core" it goes wrong again...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已更新
这应该适合您:
UPDATED
This should work for you:
要使本地任务正常工作,该路径必须直接位于父路径下。目前,您有一个额外的级别
/content/
,它将阻止选项卡显示。您的两个本地任务路径应该是:
一旦您进行了更改,清除了 Drupal 的缓存,如果您仍然不满意,请转到模块页面,禁用您的模块,单击“卸载”选项卡,然后实际卸载您的模块。重新安装后,它应该可以正常工作。
更新
我想我知道问题是什么:您期望
admin/config/guild_management_core
下的链接显示为admin/上的块中的链接config
页面...为了做到这一点,第一个菜单项的页面回调需要是:system_admin_menu_block_page()
如果不是, Drupal 不会知道将您的配置页面放在主管理配置页面上(所有核心/贡献模块也是这样做的)。
我不确定您是否能够直接在主配置页面下使用本地任务链接,因为我不确定这在 Drupal 中是否有意义,但请尝试一下。
您可以查看如何在核心
system
模块中使用system_admin_menu_block_page
的示例。For local tasks to work the path must be directly under the parent path. At the moment you have an extra level,
/content/
, which would stop the tabs from showing.Your two local task paths should be:
Once you've made that change clear Drupal's caches, and if you still get no joy go to the modules page, disable your module, click the 'Uninstall' tab, then actually uninstall your module. Once you re-install it it should work fine.
UPDATE
I think i know what the problem is: You're expecting the links under
admin/config/guild_management_core
to appear as link in a block on theadmin/config
page...in order to do this the first menu item's page callback needs to be:system_admin_menu_block_page()
If it's not, Drupal won't know to put your config page on the main admin config page (that's how all the core/contributed modules do it too).
I'm not sure you'll be able to use local tasks for the links directly under your main config page as I'm not sure that makes sense in Drupal, but try it.
You can see examples of how to use
system_admin_menu_block_page
in the coresystem
module.