0

I can't find the way to display a link in the management menu for specific roles. The link shows up only for administrator, despite all the access callbacks I tried.

In the view displayed by the page callback I declared same path, menu and access callbacks. As I don't know who is called last between module code and the view (?), I also tried with no menu nor access settings in the view.

If you could have a look at my implementation to check where I'm wrong ? Thanks a lot

function vts_dashboard_menu() {

  $items['admin/backoffice/production'] = array(
    'title' => 'Production',
    'description' => 'Edit catalogue',
    'page callback' => 'vts_dashboard_backoff_circuits',
    'access callback' => 'vts_dashboard_user_has_role',   
    'access arguments' =>  array('éditeur voyages', 'éditeur taxonomie', 'administrator'),
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'management',

    //2 alternative tests below. EVEN WITH TRUE, doesn't show up for non admin
    //'access callback' => TRUE,
    //OR ...
    //'access callback' => 'node_access',
    //'access arguments' => array('view', 1),
  );

  $items['admin/backoffice/production/circuits'] = array(
    'title' => 'Circuits',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
    'access callback' => 'vts_dashboard_user_has_role',   
    'access arguments' =>  array('éditeur voyages', 'administrator'),
  );
  // ... more items...
);
//page callback function
function vts_dashboard_backoff_circuits(){
  $viewname = 'circuits_vts'; 
  $viewdisplay = 'backoffice_products_list';
  return views_embed_view($viewname, $viewdisplay);
}
//access callback function
function vts_dashboard_user_has_role() { 
  global $user;
  $roles = func_get_args();
  foreach ($roles as $role) {
    if (in_array($role, $user->roles)) {
      return TRUE;
    }
  }
  return FALSE; 
}

Precision : these roles can see the pages/tabs called if they access directly to the path.

1 Answer 1

0

Shame on me ! The solution relied of course in a single line of my code, shared below in case it could help somebody.

I aimed to block many admin pages access, from which the admin path, in a radical manner :

function vts_dashboard_menu_alter(&$items) {
   $items['admin']['access callback'] = 'vts_dashboard_admin_access_only';
  //more items ...  
}
function vts_dashboard_admin_access_only() {
  global $user;
  if( !in_array('administrator', $user->roles)){
    return false;
  }
  return true;
}

But $items['admin']['access callback'] blocks also descendant menus items... commented out and all's fine again !

Be what it is, if any enlightened Drupal guru can tell me how to restrict access to foo path but no foo/bar, he'll receive all my consideration !

Your Answer

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

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