Commit 7ccb2485 authored by Tim Steiner's avatar Tim Steiner
Browse files

Merge pull request #560 from erasmussen2/issue-481

Closes #481
parents b0b7c814 2fc5da98
<?php
function unl_install() {
variable_set('site_404', 'unl-404');
}
// Update blocks to have correct titles, to correspond to a profile/theme update.
......@@ -40,3 +40,12 @@ function unl_update_7112() {
);
variable_set('unl_module_whitelist', $modules);
}
/**
* If site does not have custom 404 set, set it to the central UNL page.
*/
function unl_update_7113() {
if (!variable_get('site_404')) {
variable_set('site_404', 'unl-404');
}
}
......@@ -114,8 +114,23 @@ function unl_context_page_reaction() {
function unl_page_alter(&$page) {
// Add UNLcms technical feedback link to toolbar
if (isset($page['page_top']['toolbar'])) {
$page['page_top']['toolbar']['#pre_render'][] = 'unl_toolbar_add_links';
$page['page_top']['toolbar']['#pre_render'][] = 'unl_toolbar_add_links';
}
}
/**
* Implements hook_block_list_alter().
*/
function unl_block_list_alter(&$blocks) {
// Hide all content area blocks on 404 page if using the 'unl-404' menu callback.
$status = drupal_get_http_header('status');
if ($status == '404 Not Found' && variable_get('site_404') == 'unl-404') {
foreach ($blocks as $key => $block) {
if (in_array($block->region, array('content', 'sidebar_first', 'sidebar_second'))) {
unset($blocks[$key]);
}
}
}
}
/**
......@@ -255,6 +270,17 @@ function unl_permission() {
);
}
/**
* Implements hook_preprocess_node().
*/
function unl_preprocess_node(&$vars) {
// Full page representation wanted for 404 page
$status = drupal_get_http_header('status');
if ($status == '404 Not Found') {
$vars['page'] = TRUE;
}
}
/**
* Implements hook_preprocess_page().
*/
......@@ -278,11 +304,19 @@ function unl_preprocess_page(&$vars) {
}
/**
* Implementation of hook_menu().
* Implements hook_menu().
*/
function unl_menu() {
$items = array();
// 404 page pulled from default site.
$items['unl-404'] = array(
'title' => 'Page not found',
'access callback' => TRUE,
'page callback' => 'unl_404_page',
'type' => MENU_CALLBACK,
);
// Output html snippets for regions.
$items['sharedcode/%'] = array(
'title' => 'sharedcode files',
......@@ -377,7 +411,7 @@ function unl_menu() {
}
/**
* Implementation of hook_menu_alter().
* Implements hook_menu_alter().
*/
function unl_menu_alter(&$items) {
// This duplicates the form at admin/appearance/settings/unl_wdn for roles that can't 'administer themes' but have 'unl theme settings' permission.
......@@ -405,6 +439,34 @@ function unl_menu_alter(&$items) {
$items['admin/modules/uninstall']['access callback'] = 'unl_user_is_administrator';
}
/**
* Custom page callback.
*/
function unl_404_page() {
$database = $GLOBALS['databases']['default']['default'];
$database['prefix'] = unl_get_shared_db_prefix();
Database::addConnectionInfo('default_site', 'default', $database);
// Switch database connection to default site.
db_set_active('default_site');
$default_404 = unl_shared_variable_get('site_404');
// @TODO: $default_404 should look like "node/182" but is there a safer way to retrieve nid?
$node = node_load(substr($default_404, 5));
if ($node) {
drupal_set_title($node->title);
$build = node_view($node, 'full');
$build['links']['#access'] = FALSE;
$build['#contextual_links'] = NULL;
}
else {
$build = array();
}
// Restore database connection.
db_set_active();
return drupal_render($build);
}
/**
* Custom function that creates html snippet output at sharedcode/% paths to
* mimic files that once existed on static UNL templated sites.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment