drupal 7 hook_menu() 不工作

发布于 2024-12-17 18:09:29 字数 1814 浏览 0 评论 0原文

我正在尝试向“主页”>“管理”>“配置”页面添加一个部分,然后打开一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北音执念 2024-12-24 18:09:29

已更新

这应该适合您:

function tbff_promo_menu() {
    $items['admin/config/guild_management'] = array(
        'title' => 'Create Game',
        'description' => 'Create Game.',
        'position' => 'right',
        'weight' => -20,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('access administration pages'),
        'file' => 'system.admin.inc',
    );
    $items['admin/config/guild_management/core'] = array(
        'title' => 'Create Game',
        'description' => 'Create Game',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('search_block_form'),
        'access arguments' => array('access administration pages'),
        'type' => MENU_NORMAL_ITEM
    );
    $items['admin/config/guild_management/core/create_game'] = array(
        'title' => 'Create Game',
        '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('search_block_form'),
        'access arguments' => array('access administration pages'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 0,
    );
    return $items;
}

UPDATED

This should work for you:

function tbff_promo_menu() {
    $items['admin/config/guild_management'] = array(
        'title' => 'Create Game',
        'description' => 'Create Game.',
        'position' => 'right',
        'weight' => -20,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('access administration pages'),
        'file' => 'system.admin.inc',
    );
    $items['admin/config/guild_management/core'] = array(
        'title' => 'Create Game',
        'description' => 'Create Game',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('search_block_form'),
        'access arguments' => array('access administration pages'),
        'type' => MENU_NORMAL_ITEM
    );
    $items['admin/config/guild_management/core/create_game'] = array(
        'title' => 'Create Game',
        '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('search_block_form'),
        'access arguments' => array('access administration pages'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 0,
    );
    return $items;
}
灯下孤影 2024-12-24 18:09:29

要使本地任务正常工作,该路径必须直接位于父路径下。目前,您有一个额外的级别 /content/,它将阻止选项卡显示。

您的两个本地任务路径应该是:

admin/config/guild_management_core/create_game
admin/config/guild_management_core/create_team

一旦您进行了更改,清除了 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:

admin/config/guild_management_core/create_game
admin/config/guild_management_core/create_team

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 the admin/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 core system module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文