2

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

Community
  • 1
  • 1
Napoleon
  • 1,072
  • 5
  • 17
  • 31

2 Answers2

4

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;
}
Vlad Stratulat
  • 1,296
  • 1
  • 10
  • 24
  • That's not the issue, OP is expecting the links to show up in a block at `/admin/config` which it won't with the code you've provided – Clive Nov 24 '11 at 15:59
  • @Clive - first $item create menu normal item which shows in admin block. second $item defines it as default local task, and third $item generates second tab. – Vlad Stratulat Nov 24 '11 at 16:07
  • @VladStraulat: I've just tried your code, as expected the block and links do not show on the `admin/config` page. – Clive Nov 24 '11 at 16:11
  • Same conclusion. They do show in the configuration section of the admin module but not in the regular admin/config page. This would be a nice workaround tough but it's indeed not what I meant. – Napoleon Nov 24 '11 at 16:16
  • @Napoleon - please check my updated answer. I've just tested and I have block in my configuration page. Hope it will help. Cheers. – Vlad Stratulat Nov 24 '11 at 16:41
  • I changed "guild_management/core" to "guild_management_core" in your example but still nothing... Am I missing some setting somewhere? – Napoleon Nov 24 '11 at 17:10
  • Yes! In my example I reserved `guild_management` path for creating new block in Configuration. If you want your path to be `guild_management_core`, then you need to reserve another path for your block. For example `admin/config/guild` and then add your new items with paths like `admin/config/guild/guild_management_core`, `admin/config/guild/guild_management_core/create_game` etc. – Vlad Stratulat Nov 24 '11 at 17:23
3

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.

Clive
  • 36,918
  • 8
  • 87
  • 113
  • still no success. No error message but also no link on the administration page is showing. – Napoleon Nov 24 '11 at 15:25
  • Can you get to the path `admin/config/guild_management_core/create_team` directly? – Clive Nov 24 '11 at 15:26
  • Yes that shows a form with 2 tabpages "Create game" and "Create team". But for some reason the link on the admin page to it is missing. I also don't have a "Configure" button on the module in the "Modules" section but I'm not sure if those 2 are related. – Napoleon Nov 24 '11 at 15:30
  • @user653160: They're not related, the configure link comes from the module's `.info` file. I've updated the answer hope it helps – Clive Nov 24 '11 at 15:43
  • Yes I expect them in a block there. But I noticed that they DO appear on the page but as tabpages on the admin page... That's far from desired. I tried a code sample from the Annotation module (See new section in first post) and that one does work. I can however find no way to transform it to something my module can use. – Napoleon Nov 24 '11 at 15:56
  • I also tried the code sample on http://drupal.org/node/1251942 This one also does not work... – Napoleon Nov 24 '11 at 16:09