Skip to main content
1 of 2
Scott Lawrence
  • 1.2k
  • 1
  • 20
  • 62

Using hook_menu to add a child to a menu item

So I create a menu item called Sponsorship in administration in the following way:

function eac_sponsorship_menu() {
  $items['admin/sponsorship'] = array(
    'title' => 'Sponsorship',
    'description' => 'This is where all of the child sponnsorship data is stored',
    'page callback' => 'system_admin_menu_block_page',
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
    'access callback' => 'user_access',
    'access arguments' => array('access sponsorship section'),
    'plid' => 1,
    'weight' => -500,
    'expanded' => TRUE,
  );
    return $items;
}

If I want to create another menu item directly after this, in the same function, how do I make it a child to this previously defined 'Sponsorship' menu item?

I have seen examples that use a DB lookup to get the plid value. This seems a bit counter intuitive bearing in mind I've only just created the Sponsorship menu item, is there a simple way to do this using the API?

For example

$items['admin/sponsorship/child'] = array(
  'plid' => //simple API function to get admin/sponsorship mid?
}
    
Scott Lawrence
  • 1.2k
  • 1
  • 20
  • 62