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
- Install drupal 7.41
- Install Menu Item fields 7.x-1.0-alpha2
- Use PHP 5.3.26
- Enable User menu in Menu fields Tab (http://d7tests.local.mac/admin/structure/menu/menu-fields).
- Add a field and click save.
- The Access denied page should appear.
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+.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | access-denied-on-field-creation-2631602-2.patch | 426 bytes | espurnes |
Comments
Comment #2
espurnesUpload the patch described above.
Comment #3
espurnesComment #4
espurnesComment #6
4kant commentedI can confirm that #2 works.
Thanks!
Comment #7
kala4ekAlready committed to latest dev.
Comment #9
anup04sustAt function menu_fields_entity_info()
Its work for me changed "access arguments"