0

I have a new Drupal installation; when I installed my first module, I got the following error:

Undefined index: link path in menu_link_save() (line 3113 of /includes/menu.inc). error.

I have seen the line 3113 of menu.inc but I don't understand what happened. The error happen every time I install a custom module.

Does anybody know what the problem is?

This is the code I am using.

function froga_menu() {
  $items = array();
  $items['anunciantes'] = array(
    'title' => 'Editar perfil',
    'description' => 'Editar perfil - Anunciante',
    // 'parent' => array('anunciantes'),
    // 'page callback' => 'drupal_get_form',
    // 'page arguments' => array('form_editar_perfil'),
    'access callback' => TRUE,
    'type' => 'MENU_NORMAL_ITEM',
    'menu_name' => 'main-menu',
    'customized' => 1, // Must be 1 in order to not dispaly the link in any language
    'language'  => 'es', // language is required in order to make the item translatable
  );

  $mlid = menu_link_save($menu_item); // You don't need to receive it in a variable
  $ml = menu_link_load($mlid); // I'm loading $mlid just to display the result and verify it

  return $items;
}
  • Can you provide more details? Was the site working after the fresh install? What module did you install that threw this error? – Craig Jan 28 '14 at 13:06
  • 2
    This question appears to be off-topic because it is a bug report that should be posted in module's issue queue, not here. – Mołot Jan 28 '14 at 13:08
  • That module is a simple module that shows a main-menu item. It seams that the error appears when I install a custom module. – more770 Jan 28 '14 at 13:14
  • @more770 If this is a contrib module please provide the name, if it's a custom module, please provide the code. It's literally impossible to help you otherwise. This doesn't happen on a stock install of Drupal, so you have dodgy code in either a contrib or custom module – Clive Jan 28 '14 at 13:30
  • I have edited the question, you have there the code. – more770 Jan 28 '14 at 13:43
1

You are using the correct function (menu_link_save()), but you are passing it the wrong arguments, and you are calling it from the wrong hook.

The array key you can pass in &$item are described in the function documentation; the ones marked as (required) are required, and you need to pass them.

  • link_path: (required) The path of the menu item, which should be normalized first by calling drupal_get_normal_path() on it.
  • link_title: (required) Title to appear in menu for the link.
  • menu_name: (optional) The machine name of the menu for the link. Defaults to 'navigation'.
  • weight: (optional) Integer to determine position in menu. Default is 0.
  • expanded: (optional) Boolean that determines if the item is expanded.
  • options: (optional) An array of options, see l() for more.
  • mlid: (optional) Menu link identifier, the primary integer key for each menu link. Can be set to an existing value, or to 0 or NULL to insert a new link.
  • plid: (optional) The mlid of the parent.
  • router_path: (optional) The path of the relevant router item.

hook_menu() is used to tell Drupal which menu paths the module is using, not for saving a menu link when the module is installed. For that there is hook_install() or, in alternative, hook_enable() which is called every time the module is enabled, even after the module is installed; in the case you use the latter, the code needs also to check the menu link is not already present. As side note, hook_enable() is not used from Drupal 8.

|improve this answer|||||

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