2

I'm building an internal portal for an organisation and I want to change the standard administration menu, putting a number of the front-facing website options under a menu item called 'Website' and the rest under 'Drupal Config'.

So I'm simply trying to change the plid of 'admin/content', but it's not working. Could somebody guide me on where I'm going wrong please?

function eac_sponsorship_menu_alter(&$items) {

    $items['admin/content']['plid'] = 592; //592 is id of 'Website' menu item
    menu_link_save($items);

}

Also are there likely to be any repercussions from doing this?

Note that in the final solution the plid wont be hard coded as "592", but will use a DB look up to get the mlid of the 'Website' menu.

Also it is not a cache issue, when checking the DB the plid of admin/content remains to be '1'.

  • Is there a particular reason you're not doing this in configuration (and exporting a Feature if needed)? – beth Feb 7 '13 at 15:38
  • As in using the menu interface in 'Structure'? The module has the potential to be used on a number of sites so I want the ability to simply upload and deploy. – Scott Lawrence Feb 7 '13 at 15:44
  • Menus created via the GUI can be exported using Features. – beth Feb 7 '13 at 16:02
  • 1
    This seems like an unnecessary dependency just for a menu alteration. – Scott Lawrence Feb 7 '13 at 16:04
  • Hard-coding a plid seems less portable, which is something you said you wanted? Anyway, what is "not working" exactly? Did you already look whether it appears in the menu admin screen, and is just not enabled? – beth Feb 7 '13 at 16:23
2

In my example here I'm using hook_flush_caches instead of hook_menu_alter.

Also you can replace/alter db_select to return list of menu links you need to change.

/**
 * Implements hook_flush_caches().
 */
function eac_sponsorship_flush_caches() {

  $mlid = db_select('menu_links', 'ml')
    ->fields('ml', array('mlid'))
    ->condition('menu_name', 'management')
    ->condition('link_path', 'admin/content')
    ->execute()
    ->fetchField();

  if($mlid) {

    $item = menu_link_load($mlid);
    $item['customized'] = 1;
    $item['plid'] = 592; //592 is id of 'Website' menu item
    menu_link_save($item);
  }
}

also don't forget to clear/flush Drupal cache.

3

If you want your own top level admin menu group, you should probably create your own parent menu item and section there using hook_menu

e.g admin/website and put your menu items under that.

/**
 * Implements hook_menu
 */
function my_module_menu(){

  $items = array();

  // Provide own admin configuration menu section
  // using system_admin_menu_block_page for item groups
  // Top level section
  $items['admin/website'] = array(
    'title' => 'Website', 
    'description' => 'Local website configuration.', 
    'page callback' => 'system_admin_menu_block_page', 
    'access arguments' => array('access administration pages'), 
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
  );
  // Child admin menu group
  $items['admin/website/config'] = array(
    'title' => 'Configuration',
    'description' => 'Configure website settings.',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
    'weight' => 50,
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
  );
  // Child group menu item
  $items['admin/website/config/advanced'] = array(
    'title' => 'Advanced settings',
    'description' => 'Configure advanced website settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_website_settings_form'),
    'access arguments' => array('administer site configuration'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'includes/my_module.admin.inc',
  );

  return $items;

}

See system_menu for an example hook_menu using system_admin_menu_block_page

  • Hey @David-Thomas, I have created admin/website in this way but I what I am trying to achieve is to move the existing Admin menu items 'Content', 'Structure' and 'Appearance' to be children of this. – Scott Lawrence Feb 9 '13 at 13:00
0

I am using this https://drupal.stackexchange.com/a/53531/12153

That way I tweak menus depending on weather the user logged in or not. I also used it to slightly change the secondary menu.

Together with menu_rules which allows me to add new links, I have full control over what my menus do. So far I had no issues with this solution.

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.