2

I'm trying to make multiple access denied pages and show the relevant one based on the page attempted to view.

Use case:

User is limited to only one "CV" node. If they try to create another, they get an access denied page. I want to display a custom page that says something like, "You can only create one CV". A different access denied page, resulting from a different url, would display a different message.

Is this possible? The only solutions I've found seem to create a single page for all access denied notifications.

Cheers, Oliver

0

I think you what you need is: hook_node_access($node, $op, $account) https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_access/7

Parameters

$node: Either a node object or the machine name of the content type on which to perform the access check.

$op: The operation to be performed. Possible values:

"create" "delete" "update" "view" $account: The user object to perform the access check operation on.

Base on the return values, you can redirect them to custom error page. Example:

function hook_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node->type;

  if (in_array($type, node_permissions_get_configured_types())) {
   if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
    $query = drupal_get_destination();
    drupal_goto('node/custom-error-page',$query);      
   }
 }

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.