Notice: Undefined offset: 2 in _menu_translate() (line 759 of /var/aegir/drupal7/includes/menu.inc).
    Notice: Undefined offset: 2 in _menu_translate() (line 762 of /var/aegir/drupal7/includes/menu.inc).
    Notice: Undefined offset: 2 in _menu_translate() (line 759 of /var/aegir/drupal7/includes/menu.inc).
    Notice: Undefined offset: 2 in _menu_translate() (line 762 of /var/aegir/drupal7/includes/menu.inc).

Receiving the above errors. From what I can tell its related to menu_block/custom_menu_active_trail.inc.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Babalu’s picture

Project: Menu Block » Drupal core
Version: 7.x-3.x-dev » 7.8
Component: Code » menu system

Notice: Undefined offset: 2 in _menu_translate() (Zeile 762 von /var/www/vhosts/.........../httpdocs/includes/menu.inc).

handokozhang’s picture

I do have same problem: line 762 ....

Not very sure, but if I'm not wrong I never got this error but only after upgrade to 7.8 Drupal Core.

webankit’s picture

+1

sreynen’s picture

I'm having the same problem. I have a Views page display with a path of /admin/appearance/fontyourface/browse/% and a hook_menu() callback with a path of /admin/appearance/fontyourface/browse. When I load the latter, this notices comes up, where $link_map matches the former. My menu callbacks are all working as expected, outside this notice.

I'm not sure if this is the best solution, but changing menu.inc line 761 to if ($link_map[$i] == '%' && isset($path_map[$i])) { removes the notice.

StephenRobinson’s picture

I get this with D7.9 from search/*

Notice: Undefined offset: 2 in _menu_translate() (line 762 of /www/www-staging/drupal.sandbox.sanger.ac.uk/htdocs/includes/menu.inc).
aspilicious’s picture

Do you have "Menu block" enabled?

StephenRobinson’s picture

Yes, Menu Block 7.x-2.2....
Stephen :)

StephenRobinson’s picture

Disabling Menu Block makes no differences to this error.

aspilicious’s picture

Did you clear the caches after disabling? I'm prety sure this is caused by contrib modules.

StephenRobinson’s picture

perhaps it is from apache solr?

minnur’s picture

I was able to fix this, please see and try:

WAS:
1. My hook_menu implementation:

<?php
function mymodule_menu() {
  $items['admin/content/mymodule/%/details'] = array(
    'title' => 'Details page',
    'page callback' => '_mymodule_tab_callback',
    'page arguments' => array(3),
    'access arguments' => array('access details'),
    'type' => MENU_LOCAL_TASK,
  );
}
?>

Fix:
2. hook_menu().

<?php
function mymodule_menu() {
  $items['admin/content/mymodule/%mymoduleid/details'] = array(
    'title' => 'Details page',
    'page callback' => '_mymodule_tab_callback',
    'page arguments' => array(3),
    'access arguments' => array('access details'),
    'type' => MENU_LOCAL_TASK,
  );
}
?>

3. function mymoduleid_to_arg().

<?php
function mymoduleid_to_arg($arg) {
  if ($arg == '%') {
    return 'none';
  }
  else {
    return $arg;
  }
}
?>
StephenRobinson’s picture

Notice: Undefined offset: 2 in _menu_translate() (line 762 of /www/www-staging/drupal.sandbox.sanger.ac.uk/htdocs/includes/menu.inc).

done some debug, something wrong with solr:

      $link_map[$i] = $path_map[$i];
      if(!isset($path_map[$i])){
        drupal_set_message('router_item<pre>' . htmlspecialchars(print_r($router_item,1)) . '</pre>');
        drupal_set_message('map<pre>' . htmlspecialchars(print_r($map,1)) . '</pre>');
        drupal_set_message('to_arg= ' . $to_arg);
      }

heres the item

#router_item

Array
(
    [path] => search/users/%
    [load_functions] => Array
        (
            [2] => 
        )

    [to_arg_functions] => 
    [access_callback] => user_access
    [access_arguments] => a:1:{i:0;s:14:"search content";}
    [page_callback] => apachesolr_search_custom_page
    [page_arguments] => a:3:{i:0;s:24:"_apache_solr_user_search";i:1;s:0:"";i:2;i:2;}
    [fit] => 6
    [number_parts] => 3
    [tab_parent] => search
    [tab_root] => search
    [title] => Search Users
    [title_callback] => apachesolr_get_user_title
    [title_arguments] => a:2:{i:0;s:24:"_apache_solr_user_search";i:1;i:2;}
    [type] => 132
    [description] => 
    [position] => 
    [weight] => 0
    [include_file] => sites/all/modules/contrib/apachesolr/apachesolr_search.pages.inc
    [delivery_callback] => 
    [context] => 1
    [theme_callback] => 
    [theme_arguments] => a:0:{}
)
# map

Array
(
    [0] => search
    [1] => site
)

# to_arg= 1
StephenRobinson’s picture

Category: support » bug

Ah yes, is a bug in apachesolr_search.module:

    $items[$search_page->search_path] = array(
      'title' => $page_title,
      'load arguments' => array('%map', '%index'),
      'page callback' => 'apachesolr_search_custom_page',
      'page arguments' => array($search_page->page_id, '', $position), 
      'access arguments' => array('search content'),
      'type' => ($core_search) ? MENU_LOCAL_TASK : MENU_SUGGESTED_ITEM,
      'file' => 'apachesolr_search.pages.inc',
      'file path' => drupal_get_path('module', 'apachesolr_search'),
    );

%map has 2 items, not 3 before you search, hence the error.
Issue moved to apache solr - http://drupal.org/node/1364824

Damien Tournoud’s picture

Category: bug » support
Daniel_KM’s picture

Category: bug » support

Hi,

I've got the same issue and use an updated fix of the #4 above, because the bug occurs on lines 765 and 768 of menu.inc too:

  for ($i = 0; $i < $router_item['number_parts']; $i++) {
    if (isset($path_map[$i])) {
      if ($link_map[$i] == '%') {
        $link_map[$i] = $path_map[$i];
      }
      if (isset($tab_root_map[$i]) && $tab_root_map[$i] == '%') {
        $tab_root_map[$i] = $path_map[$i];
      }
      if (isset($tab_parent_map[$i]) && $tab_parent_map[$i] == '%') {
        $tab_parent_map[$i] = $path_map[$i];
      }
    }
  }

Sincerely,

Daniel Berthereau
Infodoc & Knowledge management

Daniel_KM’s picture

My issue is resolved: in fact, I've got a my_menu/my_submenu/% menu item, but no my_menu/my_submenu item.
So, as I don't want to create two items, I keep only this second one, because page argument is automatically send to function.

Sincerely,

Daniel Berthereau
Infodoc & Knowledge management

sun’s picture

alberto56’s picture

One way to reproduce this problem in D7 is to create a module with this code:

function undefined_offset_menu() {
  $items = array();

  $items['undefined_offset'] = array(
    'access callback' => TRUE,
    'page callback' => 'undefined_offset_page',
    'page arguments' => array('whatever'),
    'title' => 'Undefined Offset',
  );
  $items['undefined_offset/%'] = array(
    'access callback' => TRUE,
    'page callback' => 'undefined_offset_page',
    'page arguments' => array(1),
    'title' => 'It does not make sense for a MENU_LOCAL_ACTION to have a wildcard',
    'type' => MENU_LOCAL_ACTION,
  );

  return $items;
}

function undefined_offset_page($arg = '') {
  return 'This will produce a notice only if called with the path "undefined_offset"';
}

In the above example, when calling the path "undefined_offset", Drupal attempts to create a link to the local task, but it can't because an argument is missing.

In this case, of course, the API is not being used correctly.

Cheers,

Albert.

Nitebreed’s picture

@Albert, good call. Setting my custom module menu definitions to MENU_CALLBACK instead of MENU_LOCAL_TASK also fixed these notices for me

Uncle_Code_Monkey’s picture

What is someone supposed to do when they create two Views that exhibit this problem? There's no callback function to define anywhere.

example:
View1 has a main menu of "projects"
View2 has a main menu of "projects/%/subprojects"

Any time you view the projects page, this notice occurs and the only way to avoid it is to make sure your paths do not overlap. My current workaround is to set View1's path to "project" (make it different from "projects/..."), but I would rather not have to do such a thing.

And maybe this is a Views issue and not core.

alberto56’s picture

My site is built around a weird system where it is required that menu items contain "%" and be local tasks (not recommended, but I can't seem to get rid of it). Anyway, here is a quick and dirty patch I'm using "temporarily" to avoid this error. I'm not recommending you use it, but here it is.

marcoka’s picture

i have this too if i go to /user

MariskaTh’s picture

Issue summary: View changes

#15 worked for me. Thanks!

jwilson3’s picture

Here is a re-roll of the patch in #21 for Drupal 6, which also fixes this issue for me.

joshmiller’s picture

Status: Closed (duplicate) » Reviewed & tested by the community

This is actually not a duplicate. The person who said it was a duplicate failed to note that this (albeit very similar) bug is being generated on core Drupal. We have applied the patch in #21 on a large Drupal Commerce site for the last 2 years happily.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: core--6.x--1108314-24-undef-offset.patch, failed testing. View results

Version: 7.8 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.