Undefined index: menu in admin_menu_admin_menu_output_alter() (line 612 of /var/www/sites/all/modules/admin_menu/admin_menu.module)

StackOverflow https://stackoverflow.com/questions/21796783

  •  12-10-2022
  •  | 
  •  

Вопрос

This is the error found in admin area:

  • Notice: Undefined index: menu in admin_menu_admin_menu_output_alter() (line 612 of /var/www/sites/all/modules/admin_menu/admin_menu.module).

  • Warning:Invalid argument supplied for foreach() in
    admin_menu_admin_menu_output_alter() (line 612 of
    /var/www/sites/all/modules/admin_menu/admin_menu.module).

Code is:

/**
 * Implements hook_admin_menu_output_alter().
 */
function admin_menu_admin_menu_output_alter(&$content) {
  foreach ($content['menu'] as $key => $link) {
    // Move local tasks on 'admin' into icon menu.
    if ($key == 'admin/tasks' || $key == 'admin/index') {
      $content['icon']['icon'][$key] = $link;
      unset($content['menu'][$key]);
    }
  }
}

Foreach is line:612

What is the error in this code?

Thanks in advance.

Это было полезно?

Решение 2

function admin_menu_admin_menu_output_alter(&$content) {

    // Check if index menu is defined in $content and is array
    if( !isset($content['menu']) || !is_array($content['menu']) ) 
        return;

    foreach ($content['menu'] as $key => $link) {
        // Move local tasks on 'admin' into icon menu.
        if ($key == 'admin/tasks' || $key == 'admin/index') {
              $content['icon']['icon'][$key] = $link;
              unset($content['menu'][$key]);
        }
    }
}

Другие советы

As the error says, $content['menu'] seems to be undefined, but it should be an array since you are attempting to use foreach on it. Therefore, you would need to do something like this before using it:

$content['menu'] = array('value1', 'value2');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top