Last active
August 11, 2017 20:25
-
-
Save mootari/3c5d0d2b2d5780530ee25b218de75dd7 to your computer and use it in GitHub Desktop.
Proper error pages for content editors in admin theme. #drupal #d7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_process_HOOK(). | |
*/ | |
function THEME_process_page(&$vars) { | |
$error_pages = array( | |
403 => array( | |
'title' => '403 Access Denied', | |
'text' => 'You do not have access to this path.', | |
), | |
404 => array( | |
'title' => '404 Not Found', | |
'text' => 'This path does not exist.', | |
), | |
); | |
$status = (int) drupal_get_http_header('status'); | |
if(isset($error_pages[$status])) { | |
$content = $error_pages[$status]; | |
// Content editors might have edit access to error pages. Because Drupal | |
// changes the current page's node context, we disable all local tasks to | |
// prevent accidental editing of the displayed error node. | |
$vars['primary_local_tasks'] = array(); | |
$vars['secondary_local_tasks'] = array(); | |
$vars['tabs'] = array(); | |
// Error nodes are usally meant for frontend consumption and might break | |
// when displaying them in the admin theme. | |
$vars['page']['content'] = array(); | |
$vars['title'] = check_plain(t($content['title'])); | |
$vars['page']['content']['#markup'] = check_plain(t($content['text'])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment