I just started learning drupal 7 module development. I wanted to group all my custom modules under one category (say custom). I know how to manually do that using "admin/structure/menu/manage/management". But is it possible to create a new group and put all my module menus under that group using hook_menu ?

For Example :

  function hook_menu() {
  $items['admin/settings/custom/module-name'] = array(
  //other code here

The above code doesn't create the "custom" menu item instead it creates "module-name" menu. I want to put "module-name" under "custom" ?

  • 4
    you should create $items['admin/settings/custom'] menu too – kalabro Jul 19 '12 at 10:59

Thanks to kalabro for the answer. For those who are new to module development and need the same functionality, I've posted the code below :

  function hook_menu() {
  $items['admin/settings/custom'] = array();
  $items['admin/settings/custom/module-name'] = array(
  //other code here

You can use the "$items['admin/settings/custom'] = array();" in a separate module also.

Note : Be sure to flush the cache. Sometimes you might need to disable and then enable the modules again for this to work...

  • Where should I write this code ? In which module ? – Kshitij Soni Sep 21 '17 at 6:44
  • it's required (highly suggestable) not only to disable/enable but also uninstall/install – Tormy Van Cool May 13 '19 at 8:57

The answer by Sharan didn't work with the current Drupal 7.34. An empty array will not create a new group, even after disabling and uninstalling and re-enabling the module and flushing caches and so on...

I did some research and found a way that works quite well. It will create an new item (with subitems) in the 'Management' menu, that has it's own (translatable) title and description. When the group itself is opened in a browser ('admin/config/custom' in the example), it will show an overview page that lists all the subitems with descriptions. It also integrates as expected with the menu bar from the admin_menu module.

function hook_menu() {
  // The new group
  $items['admin/config/custom'] = array(
    'title' => 'Custom settings',
    'description' => 'All the custom settings.',
    // 'position' and 'weight' can be used to place
    // the group in the the parent overview (admin/config).
    'position' => 'right',
    'weight' => -20,
    'access arguments' => array('access administration pages'),
    // This renders the group overview.
    'page callback' => 'system_admin_menu_block_page',
    // 'file' and 'file path' are required for the
    // 'system_admin_menu_block_page' callback.
    'file' => 'system.admin.inc', 
    'file path' => drupal_get_path('module','system'),
  // A subitem in the group
  $items['admin/config/custom/module-name'] = array(
    //other code here

EDIT: A cache flush should be enough to enable the group.

  • Where should I write this code ? In which module ? – Kshitij Soni Sep 21 '17 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.