You are here

footer_message.module in Footer Message 7

Same filename and directory in other branches
  1. 8 footer_message.module

This module provides a configurable footer message as a block.

File

footer_message.module
View source
<?php

/**
 * @file
 * This module provides a configurable footer message as a block.
 */

/**
 * Implements hook_form_FORM_ID_alter().
 */
function footer_message_form_system_site_information_settings_alter(&$form, &$form_state, $form_id) {

  // Add a footer text area to the "Site Information" admin page.
  // Note the use of Drupal 7's new "text format" property, described
  // http://drupal.org/update/modules/6/7#text_format. Note that both the
  // value of this 'footer_message_msg' textarea and its filter format are
  // stored as a serial value in the variables table.
  $site_footer = variable_get('footer_message_msg', array(
    'value' => 'This is default site footer content.',
  ));
  $form['footer_message_msg'] = array(
    '#type' => 'text_format',
    '#base_type' => 'textarea',
    '#title' => t('Site Footer message'),
    '#default_value' => $site_footer['value'],
    '#format' => isset($site_footer['format']) ? $site_footer['format'] : NULL,
    '#required' => FALSE,
  );
  $form['#submit'][] = 'footer_message_form_submit';
}

/**
 * Implements hook_block_info().
 */
function footer_message_block_info() {

  // Add a block containing the site footer message.
  $blocks['footer_message'] = array(
    'info' => t('Footer Message'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function footer_message_block_view($delta = '') {
  $block = array();
  switch ($delta) {

    // Display the footer message block.
    // Note that we apply the appropriate filter format before outputting HTML.
    case 'footer_message':
      $site_footer = variable_get('footer_message_msg', array(
        'value' => 'This is default site footer content.',
      ));
      $format = isset($site_footer['format']) ? $site_footer['format'] : NULL;
      $block['content'] = check_markup($site_footer['value'], $format);
      break;
  }
  return $block;
}

/**
 * Implements hook_preprocess_HOOK().
 */
function footer_message_preprocess_page(&$variables) {

  // Provide $footer_message as a theme variable to hook_preprocess_page()
  // and page.tpl.php.
  // Note that we apply filter format before outputting HTML.
  $site_footer = variable_get('footer_message_msg', array(
    'value' => 'This is default site footer content.',
  ));
  $format = isset($site_footer['format']) ? $site_footer['format'] : NULL;
  $variables['footer_message'] = check_markup($site_footer['value'], $format);
}

/**
 * Implements hook_contextual_links_view_alter().
 */
function footer_message_contextual_links_view_alter(&$element, &$items) {

  // Add contextual link for footer_message block.
  if (isset($element['#element']['#block']) && $element['#element']['#block']->delta == "footer_message") {
    $element['#links']['footer-message'] = array(
      'title' => 'Edit footer message',
      'href' => url('/admin/config/system/site-information', array(
        'external' => TRUE,
      )),
      'query' => drupal_get_destination(),
    );
  }
}

/**
 * Custom submit function for system_site_information_settings form.
 */
function footer_message_form_submit($form, &$form_state) {
  $message = $form_state['values']['footer_message_msg'];
  $element = $form['footer_message_msg'];

  // Clear the footer_message block cache.
  if ($message['value'] != $element['#default_value'] || $message['format'] != $element['#format']) {
    cache_clear_all('footer_message:', 'cache_block', TRUE);
  }
}