3

I am getting an offset error , Undefined offset: 4 in _menu_translate()

 $items['admin/content/import-dashboard/new'] = array(
    'title' => 'Import Dashboard',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('import_dashboard_new_content',"article"),
    'access arguments' => array('Import Dashboard Permission'),
    'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
    'expanded' => TRUE,
  );
    $items['admin/content/import-dashboard/new/%'] = array(
    'title' => 'Import Dashboard',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('import_dashboard_new_content',4),
    'access arguments' => array('Import Dashboard Permission'),
    'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
    'expanded' => TRUE,
  );

I simply want to default new to article, and also use wildcards to support other arguments.

I'm pretty flexible in my approach, so feel free to throw a few suggestions if it could be done better.

Can someone quickly suggest where I made my rookie mistake?


Indeed, changing to Menu Callback works when using the wildcard.

$items['admin/content/import-dashboard/new/%'] = array(
    'title' => 'Import Dashboard',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('import_dashboard_new_content',4),
    'access arguments' => array('Import Dashboard Permission'),
    'type' => MENU_CALLBACK,
    'expanded' => TRUE,
  );

Would still like to know why it fails when it a MENU_LOCAL_TASK or MENU_NORMAL_ITEM

3
  • I'm not sure you can add multiple types to a single menu item. That might be part of the issue.
    – merauluka
    Jan 22 '14 at 19:24
  • @mbent - You can...I don't think that's the problem Jan 22 '14 at 19:30
  • It's a very specific error related to using the multilingual features of Drupal. From what I've looked up and read, the reason changing the type to MENU_CALLBACK is because you're telling Drupal to ignore your arguments...I think. Maybe try taking a look at what the number 4 is doing in the page arguments. It might have something to do with the error.
    – merauluka
    Jan 22 '14 at 20:11
1

The problem is that your menu items are local tasks, which are menu tabs, so on a given page drupal will load all the tabs for the current page.

So on the admin/content/import-dashboard/new page it loads your tab menu items:
admin/content/import-dashboard/new
admin/content/import-dashboard/new/%

but when it goes to get the second item there is no 4th param on the current page so it gets that error.

This is why when you change it to not be a MENU_LOCAL_TASK it stops the problem.

If you have a page that has menu tabs where the last part of the path is a wildcard, how could drupal know what all the possible tabs are? It can't.

This is why when you see menu tabs they are things like node/%/view, node/%/edit, etc. so you have a finite number of tabs and each has its own definition.

As a side note, yes you can use multiple menu item types, but using MENU_LOCAL_TASK | MENU_NORMAL_ITEM doesn't really make sense. As an example MENU_IS_LOCAL_TASK | MENU_LINKS_TO_PARENT | MENU_VISIBLE_IN_BREADCRUMB is one that would make sense.

Also, I'm not sure if this is your full hook_menu() or if admin/content/import-dashboard exists somewhere else, but usually if you're doing tabs there is a parent page (in this case admin/content/import-dashboard) and a tab that is MENU_DEFAULT_LOCAL_TASK.

There is however the ability to set in your menu item:

'tab_parent' => 'admin/content/import-dashboard/new'

This allows you to set the parent page to use for tab items. Without this it defaults to the path of the tab item minus its last path part.

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.