I'm trying to implement my own access denied page, and I'd like to get some information about the context of the access being denied... for example, if the user is on a specific node type page, I'd like to still display a short snippet of that node before the access denied message, so the user knows he's at least in the right part of my site.
However, I can't use menu_get_object()
, as arg(0)
simply returns 'access denied' in my page callback. Is there any way of passing in the path information for an access denied page? See my code below:
<?php
/**
* Implements hook_menu().
*/
function custom_menu() {
$items['access-denied'] = array(
'title' => 'Access Denied',
'page callback' => 'custom_access_denied',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
?>
And in my page callback:
<?php
/**
* Access Denied page.
*/
function fn_custom_access_denied() {
global $user;
$html = '';
// Display access denied message and login form for anonymous users.
if (!$user->uid) {
$html .= '<p>' . t('The content you are trying to access is protected. Please log in or create an account to view the page.') . '</p>';
$html .= drupal_render(drupal_get_form('user_login'));
drupal_set_title('Login Required');
}
// Display access denied message for logged-in users.
if ($user->uid) {
$html .= '<p>' . t('The content you are trying to access is protected.') . '</p>';
drupal_set_title('Private Content');
}
return $html;
}
?>