Tuesday, May 31, 2011

Customize the Default Error reporting

Customize the Default Error reporting

go to "Admin" > Error Reporting > Set "Default 403 (access denied) page:" to:

access_denied

<?php
/**
 * Implementation of hook_menu().
 */
function myModule_menu() {
  $items = array();

  $items['access_denied'] = array(
    'title' => '',
    'page callback' => 'myModule_default_403_access_denied_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}


function myModule_default_403_access_denied_page() {
  // Customize error reporting message for some URL.
  // Note: you should use $_REQUEST['destination'] instead of $_GET['destination'].
  if ($_REQUEST['destination'] === 'user/register') {
    $title = '';
    $str = t('You have been signed as our member. Thanks for your interest.');
  }
  else {
    $title = t('Access denied');
    $str = t('You are not authorized to access this page.');
  }
  
  drupal_set_title($title);

  return $str;
}
?>

No comments: