3

how can I check user's access first based on some permission and if user passed this check then execute access callback function with some parameters in path, some thing like this:

$items['order/add/%node'] = array(
  'title' => 'Place new order',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('order_add_form', 2),
  'access callback' => 'order_add_access',
  'access arguments' => array('place order', 2),
  'type' => MENU_LOCAL_TASK,
  'file path' => drupal_get_path('module', 'order'),
  'file' => 'order.page.inc',
);

2 Answers 2

7

Not sure exactly what you mean there but your code already has a custom access callback specified as well as access arguments?

You could have an access callback like this:

/**
 * Add order access callback
 */
function order_add_access($op, $node){

 switch ($op) {
   case 'place order':
   // Return true, if logged in user has administer nodes permission
   // and node status is published.
   if (user_access('administer nodes') && $node->status == 1) {
     return TRUE;
   }
   break;
 }
 return FALSE; // default

}
2

If the first item of the access arguments is the string for the permission the user should have to access the menu item, you could use the following code.

function order_add_access($permission, $node) {
  if (user_access($permission)) {
    // Check any node property, and return TRUE when the user should access the menu item.
  }

  return FALSE;
}

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.