footer_message.module 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * This module provides a configurable footer message as a block.
  5. */
  6. /**
  7. * Implements hook_form_FORM_ID_alter()
  8. */
  9. function footer_message_form_system_site_information_settings_alter(&$form, &$form_state, $form_id) {
  10. // Add a footer text area to the "Site Information" admin page.
  11. // Note the use of Drupal 7's new "text format" property, described
  12. // http://drupal.org/update/modules/6/7#text_format. Note that both the
  13. // value of this 'footer_message_msg' textarea and its filter format are
  14. // stored as a serial value in the variables table.
  15. $site_footer = variable_get('footer_message_msg',
  16. array('value' => 'This is default site footer content.'));
  17. $form['footer_message_msg'] = array(
  18. '#type' => 'text_format',
  19. '#base_type' => 'textarea',
  20. '#title' => t('Site Footer message'),
  21. '#default_value' => $site_footer['value'],
  22. '#format' => isset($site_footer['format']) ? $site_footer['format'] : NULL,
  23. '#required' => TRUE,
  24. );
  25. }
  26. /**
  27. * Implements hook_block_info().
  28. */
  29. function footer_message_block_info() {
  30. // Add a block containing the site footer message.
  31. $blocks['footer_message'] = array(
  32. 'info' => t('Footer Message'),
  33. 'cache' => DRUPAL_CACHE_GLOBAL,
  34. );
  35. return $blocks;
  36. }
  37. /**
  38. * Implements hook_block_view().
  39. */
  40. function footer_message_block_view($delta = '') {
  41. $block = array();
  42. switch ($delta) {
  43. // Display the footer message block. Note that we apply the appropriate filter format before outputting HTML.
  44. case 'footer_message':
  45. $site_footer = variable_get('footer_message_msg',
  46. array('value' => 'This is default site footer content.'));
  47. $format = isset($site_footer['format']) ? $site_footer['format'] : NULL;
  48. $block['content'] = check_markup($site_footer['value'], $format);
  49. break;
  50. }
  51. return $block;
  52. }
  53. /**
  54. * Implements hook_preprocess_HOOK()
  55. */
  56. function footer_message_preprocess_page(&$variables) {
  57. // Provide $footer_message as a theme variable to hook_preprocess_page() and page.tpl.php.
  58. // Note that we apply filter format before outputting HTML.
  59. $site_footer = variable_get('footer_message_msg',
  60. array('value' => 'This is default site footer content.'));
  61. $format = isset($site_footer['format']) ? $site_footer['format'] : NULL;
  62. $variables['footer_message'] = check_markup($site_footer['value'], $format);
  63. }