简体   繁体   中英

drupal 7 hook_menu() not working

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

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM