You are here

blocks404.module in 404 Blocks 5

File

blocks404.module
View source
<?php

define('BLOCKS404_PAGE', 'blocks404');

/**
 * Implements hook_init().
 */
function blocks404_init() {

  // If site_404 is not set, all menu-related items disappear on 404.
  $site_404 = variable_get('site_404', '');
  if ($site_404 == '') {
    variable_set('site_404', BLOCKS404_PAGE);
  }

  // drupal_not_found() sets $_GET['q'] to the site_404 variable, so make a copy.
  define('BLOCKS404_ORIGINAL_QUERY', $_GET['q']);
}

/**
 * Implements hook_menu().
 */
function blocks404_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => BLOCKS404_PAGE,
      'title' => 'Page not found',
      'access' => TRUE,
      'callback' => 'blocks404_404_page',
      'type' => MENU_CALLBACK,
    );
  }
  return $items;
}

/**
 * Our custom menu callback that returns Drupal's standard 404 message.
 */
function blocks404_404_page() {
  return t('The requested page could not be found.');
}

/**
 * Renders the left and right regions and resets the body classes on 404 pages.
 */
function blocks404_preprocess_page(&$vars, $hook) {
  if (strpos(drupal_get_headers(), 'HTTP/1.1 404 Not Found') !== FALSE) {
    module_load_include('inc', 'blocks404', 'blocks404.active');
    _blocks404_preprocess_page($vars);
  }
}

/**
 * Implements hook_form_alter().
 */
function blocks404_form_alter($form_id, &$form) {
  if ($form_id == 'system_error_reporting_settings') {

    // Since we don't care what site_404 is set to, let the user set it if they want.
    if ($form['site_404']['#default_value'] == BLOCKS404_PAGE) {
      $form['site_404']['#default_value'] = '';
    }
  }
  elseif ($_GET['q'] == BLOCKS404_PAGE) {
    include_once './' . drupal_get_path('module', 'blocks404') . '/blocks404.active.inc';
    _blocks404_form_alter($form_id, $form);
  }
}

Functions

Namesort descending Description
blocks404_404_page Our custom menu callback that returns Drupal's standard 404 message.
blocks404_form_alter Implements hook_form_alter().
blocks404_init Implements hook_init().
blocks404_menu Implements hook_menu().
blocks404_preprocess_page Renders the left and right regions and resets the body classes on 404 pages.

Constants

Namesort descending Description
BLOCKS404_PAGE