duanjing4623
2011-11-24 15:01
浏览 61
已采纳

drupal 7 hook_menu()无法正常工作

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...

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将一个部分添加到主页>管理>配置页面,然后打开一个包含2个标签的新表单 (create_team和create_game)。

我的代码(不起作用):

  function guild_management_core_menu()
 {
 $  items ['admin / config / guild_management_core / create_game'] = array 
(
'title'=>'创建游戏',
'描述'=>'创建游戏',
'页面回调'=  >'drupal_get_form',
'页面参数'=>数组('guild_management_core_create_game'),
'访问参数'=>数组('访问管理页面'),
'类型'=> MENU_DEFAULT_LOCAL_TASK,  
'weight'=> 0,
);  
 $ items ['admin / config / guild_management_core / create_team'] = array 
(
'title'=>'创建团队',
'描述'=>'创建团队',
'页面 callback'=>'drupal_get_form',
'page arguments'=> array('guild_management_core_create_team'),
'访问参数'=>数组('访问管理页面'),
'类型'=&gt  ; MENU_LOCAL_TASK,
'weight'=> 0,
);  
 
返回$ items; 
   
 
 

}

我尝试了下面的链接,但它们也不起作用: n drupal - hook_menu 来自管理菜单模块的Drupal hook_menu

我还禁用了模块并再次启用它 然后我清除了缓存但仍然没有结果。

编辑: 这有用:

  $ items ['admin / config /  annotate'] = array(
'title'=>'公会管理',
'描述'=>'公会管理',
'位置'=>'右',
'权重'=  > -5,
'页面回调'=>'system_admin_menu_block_page',
'访问参数'=>数组('管理站点配置'),
'文件'=>'system.admin.inc  ',
'文件路径'=> drupal_get_path('module','system'),
); 
   
 
 

当我替换“admin / config时 / annotate“with”admin / config / guild_m anagement_core“它又出错......

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dthyxna3894 2011-11-24 15:56
    已采纳

    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;
    }
    
    点赞 打赏 评论
  • dragonfly9527 2011-11-24 15:11

    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.

    点赞 打赏 评论

相关推荐 更多相似问题