4

I'm trying to add a new configurations block to admin/config (just like "People", "Media" and "System").

I tried copying and modifying the relevant lines from modules/user/user.module but my block doesn't show and directly going to the link admin/config/mysite results in an access denied message.

The sub pages appear directly under the Administration > Configuration menu in the Administration module (but not in the page admin/config.)

Any idea how to fix this?

$items['admin/config/mysite'] = array(
  'title' => 'My Site',
  'description' => 'Configure My Site settings.',
  'position' => 'left',
  'weight' => -20,
  'page callback' => 'system_admin_menu_block_page',
  'access arguments' => array('access administration pages'),
  'file' => 'system.admin.inc',
  'file path' => drupal_get_path('module', 'system'),
);

$items['admin/config/mysite/page1'] = array(
  'title' => 'Sub page 1',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('mysite_admin_1'),
  'access arguments' => array('access administration pages'),
);

$items['admin/config/mysite/page2'] = array(
  'title' => 'Sub page 2',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('mysite_admin_2'),
  'access arguments' => array('access administration pages'),
);

4 Answers 4

2

I have solved my own problem. The reason the links appeared where they did and not under my new block is that I've moved existing items to a new location, which means they were still in the original location in the menu configuration screen. Moving them manually to their correct location solved the problem.

0
0

if we don't specify the access callback property in hook_menu() we get a notification as below:

Notice: Undefined index: access in _menu_translate() (line 778 of includes/menu.inc).
Notice: Undefined index: access in menu_get_item() (line 464 of includes/menu.inc).
Notice: Undefined index: access in menu_execute_active_handler() (line 499 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of incldes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_local_tasks() (line 1845 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).

To avoid this the above code should be edited a bit by adding an access callback property

$items['admin/config/mysite'] = array(
 'title' => 'My Site',
 'description' => 'Configure My Site settings.',
 'position' => 'left',
 'weight' => -20,
 'page callback' => 'system_admin_menu_block_page',
 'access callback' => 'user_is_admin'
 'access arguments' => array('access administration pages'),
 'file' => 'system.admin.inc',
 'file path' => drupal_get_path('module', 'system'),
);

$items['admin/config/mysite/page1'] = array('title' => 'Sub page 1',
 'page callback' => 'drupal_get_form',
 'page arguments' => array('mysite_admin_1'),
 'access callback' => 'user_is_admin'
 'access arguments' => array('access administration pages'),
);

And the notice is removed. :)

1
  • No this will result in an error that "user_is_admin" function is not defined. Also, "access callback" defaults to "user_access" so it's not necessary to define it unless overriden somewhere else either.
    – AKS
    Commented Nov 3, 2012 at 22:42
0

I fixed it using below code.

$items['admin/config/myblk'] = array(
'title' => 'Title of the block',
'description' => 'description',
'position' => 'left',
'weight' => -25,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
);

$items['admin/config/myblk/myblk-setting'] = array(
'title' => 'Link to settings',
'description' => 'Description about link',
'page callback' => 'drupal_get_form',
'page arguments' => array('call_your_setting_form'),
'access arguments' => array('administer authentication'),
'weight' => 10,
);

enter image description here

0

The easiest way we can add the module link to Admin config page by menu management. Here is the below link to access the menu management.

http://yoursite.com/admin/structure/menu/manage/management

Thank you!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.