Problem/Motivation

Access denied (You are not authorized to access this page.) message when trying to save new menu field or configure an existing one.

I used user_menu as a test menu to add fields to it. The folowing code is looking for User menu inside an array of enabled_menus. The problem is that $menu stores user_menu and $enabled_menus stores user-menu. So the if statment return FALSE and denies access to administer the fields.

menu_fields.module (line 743)

function menu_fields_admin_access($menu) {
  $enabled_menus = menu_fields_enabled_menus();
  if (!in_array($menu, $enabled_menus)) {
    return FALSE;
  }
  return user_access('administer menu fields');
}

This issue happens with all the menus with more than one word (Main menu, User menu). Only the menus with one word works because there is no '-' or '_' involved.

Behaviour reproduced in Drupal 7.41 fresh install (profile standard) with Menu Item Fields 7.x-1.0-alpha2
PHP 5.3.26

I'm not able to reproduce it in simplytest.me because it is using PHP 5.5

Steps to reproduce the issue

Proposed resolution

Option 1
Use PHP 5.4.42+
I tested with PHP 5.5.42 and 5.5.26 and the wrong behaviour is gone.

Option 2 (using PHP 5.3.26)
Replace '_' with '-'

function menu_fields_admin_access($menu) {
  $menu = str_replace('_', '-', $menu);
  $enabled_menus = menu_fields_enabled_menus();
  if (!in_array($menu, $enabled_menus)) {
    return FALSE;
  }
  return user_access('administer menu fields');
}

This patch works also in 5.4.42+.

Comments

espurnes created an issue. See original summary.

espurnes’s picture

Upload the patch described above.

espurnes’s picture

Issue summary: View changes
espurnes’s picture

Status: Active » Needs review

4kant’s picture

I can confirm that #2 works.
Thanks!

kala4ek’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Status: Needs review » Fixed

Already committed to latest dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anup04sust’s picture

At function menu_fields_entity_info()
Its work for me changed "access arguments"

    $bundles[$machine_name]['admin'] = array(
        'path' => 'admin/structure/menu/manage/%',
        'real path' => 'admin/structure/menu/manage/' . str_replace('_', '-', $machine_name),
        'bundle argument' => 4,
        'access callback' => 'menu_fields_admin_access',
        'access arguments' => array(str_replace('_', '-', $machine_name)),
      );