1

When I add menu items manually, they work fine. When I try this I get no delete link in the admin, and I can't edit the menu items.

$link = array();
$link['link_title'] = "text";
$link['link_path'] = 'node';
$link['menu_name'] = $menu;
$link['expanded'] = 1;
$link['module'] = "dl_migration";
$link['weight'] = $i;
menu_link_save( $link );
menu_cache_clear_all();

2 Answers 2

2

The reason the "delete" link is not shown is that the link is only shown when the menu item is created by (or associated to) the Menu module. _menu_overview_tree_form() contains the following code:

  // Only items created by the menu module can be deleted.
  if ($item['module'] == 'menu' || $item['updated'] == 1) {
    $operations['delete'] = l(t('delete'), 'admin/build/menu/item/' . $item['mlid'] . '/delete');
  }

menu_link_save() uses some defaults for the array $item passed as argument; this means that if the module associated with the menu link is not explicitly set, it receives the default value ("menu").

  // Load defaults.
  $item += array(
    'menu_name' => 'navigation', 
    'weight' => 0, 
    'link_title' => '', 
    'hidden' => 0, 
    'has_children' => 0, 
    'expanded' => 0, 
    'options' => array(), 
    'module' => 'menu', 
    'customized' => 0, 
    'updated' => 0,
  );
4
  • Uhm, yeah, that's what I said above. Thanks for fleshing out the answer tho. It's a stupid paradigm though, don'tcha think?
    – jhchnc
    Commented Sep 22, 2011 at 15:06
  • 3
    I think the idea is that users should not be allowed to delete links programmatically added by third-party modules; users should just be able to disable those links. It makes perfectly sense to me, especially in the case a module help text makes reference to those links.
    – avpaderno
    Commented Sep 22, 2011 at 15:52
  • It should be an option -- during the large migration I'm setting up we are going to be using a module to create a set of menus. Marking those with our module name is preferable because it limits things conceptually. Ah well.
    – jhchnc
    Commented Sep 22, 2011 at 16:00
  • 1
    You can propose a feature request for Drupal. It would help to have a flag that allows to modules to create a menu link that can be deleted from users, even if the value for "module" is not "menu." In that way, a module could add custom links users can delete, and still be able to delete the links when it is uninstalled.
    – avpaderno
    Commented Sep 25, 2011 at 15:05
1

Specifying the module name is what caused the lack of ability to delete. I'm not sure why, though. Sort of lame I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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