0

Is there a simple way to give access to 1 panel of options within Administration Configuration? I made a custom module with settings under /admin/config/mymodule and it shows up as a block with links in the admin config area.

But I cant see how to easily say Role X can access that -- without giving global access admin configuration in Permissions, which lets them see everything there :(.

My example hook_menu is:

function predeparture_menu() {
  $items = array();
  $items['admin/config/eap-predeparture'] = array(
    'title' => 'Manage Site',
    'description' => 'upload the valid predeparture csv file from this page.',
    'position' => 'left',
    'weight' => -100,
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('administer site configuration'),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );
  // Need at least one child item before your section will appear.
  $items['admin/config/eap-predeparture/list'] = array(
    'title' => 'Student Predeparture List',
    'description' => 'Upload, Revise or Rebuild the student perm list to administer access to the predeparture survey.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('predeparture_csv_admin_form'),
    'access arguments' => array('administer site configuration'),
    'weight' => 10,
  );
  $items['admin/config/eap-predeparture/incomplete'] = array(
    'title' => 'Not Yet Completed Orientation Report',
    'description' => 'These students have not completed the Predeparture survey based on those in the CSV file.',
    'page callback' => 'predeparture_incomplete_listing',
    'access arguments' => array('administer site configuration'),
    'weight' => 20,
  );
  return $items;
}
1

Create your own permission in your module

function predeparture_permission() {
  return array(
    'administer my module' => array(
      'title' => t('Administer my module'),
      'description' => t('Perform administration tasks for my module.'),
    ),
  );
}

Then your menu item should have

'access arguments' => array('administer my module')

And check this permission for the role you want in the permissions page: admin/people/permissions

  • I used this solution to enable access. But they cant see the menu path in like the Admin Menu or anywhere -- they have to goto the URL directly. Any idea how to see the Admin Configuration but dissallow all modules that aren't my own for X role ? .... wizardy in hook_menu_alter ? – tenken Sep 23 '13 at 21:07
  • you could create a custom link to access directly to this page – pico34 Sep 24 '13 at 7:12
  • 1
    Custom Permissions can maybe help you – pico34 Sep 24 '13 at 7:14
  • thanks. Custom Permissions looks like what I've been looking for -- your general solution is still great. – tenken Sep 24 '13 at 16:08
1

you can write your own "access callback" function returning TRUE just if the current user have the role you choose. Something like this:

function predeparture_menu() {
  $items = array();
  $items['admin/config/eap-predeparture'] = array(
    'title' => 'Manage Site',
    'description' => 'upload the valid predeparture csv file from this page.',
    'position' => 'left',
    'weight' => -100,
    'page callback' => 'system_admin_menu_block_page',
    'access callback' => 'my_access_callback',
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );

function my_access_callback() {
  global $user;
  return in_array('the role', $user->roles);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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