site_status_message.module in Site Status Message 7
Same filename and directory in other branches
Site Status Message provides a configurable page top message.
@author: Gideon Cresswell (DrupalGideon) <https://www.drupal.org/u/drupalgideon>
File
site_status_message.moduleView source
<?php
/**
* @file
* Site Status Message provides a configurable page top message.
*
* @author: Gideon Cresswell (DrupalGideon)
* <https://www.drupal.org/u/drupalgideon>
*/
/**
* Implements hook_help().
*/
function site_status_message_help($path, $arg) {
switch ($path) {
case 'admin/help#site_status_message':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Site Status Message is a simple module to display a site wide message to your users at the top of each page. Use cases could be to inform of known downtime in the future, to advertise a special offer on the site or some important news that needs highlighting.') . '</p>';
$output .= '<p>' . t('An optional link to a page with more information can be displayed after the message.') . '</p>';
$output .= '<p>' . t('The settings for this module can be configured on the <a href="@url">Site Status Message Administration</a> page.', array(
'@url' => '/admin/config/system/site-status-message',
)) . '</p>';
return $output;
}
return NULL;
}
/**
* Implements hook_permission().
*/
function site_status_message_permission() {
return array(
'administer site status message' => array(
'title' => t('Administer Site Status Message'),
'description' => t('Access the Site Status Message administration pages.'),
),
);
}
/**
* Implements hook_page_menu().
*/
function site_status_message_menu() {
$items = array();
$items['admin/config/system/site-status-message'] = array(
'title' => 'Site Status Message',
'description' => 'Configure settings for the Site Status Message.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'site_status_message_settings',
),
'access arguments' => array(
'administer site status message',
),
'type' => MENU_NORMAL_ITEM,
'weight' => 50,
'file' => 'site_status_message.admin.inc',
);
return $items;
}
/**
* Implements hook_page_build().
*/
function site_status_message_page_build(&$page) {
$site_status_message = trim(variable_get('site_status_message_message', NULL));
// If the message is blank, do not display.
if ($site_status_message) {
$page_option = variable_get('site_status_message_display_options', 'off');
$admin_page = path_is_admin(current_path());
// Check if the message should be displayed at all for this path.
if ($page_option === 'off' || $page_option === 'public' && $admin_page || $page_option === 'admin' && !$admin_page) {
return;
}
$variables = array();
$variables['message'] = token_replace($site_status_message);
$variables['link'] = variable_get('site_status_message_link', NULL);
/* @noinspection PhpUnhandledExceptionInspection */
$page['page_top']['site_status_message'] = array(
'#type' => 'markup',
'#markup' => theme('site_status_message', $variables),
'#attached' => array(
'css' => array(
drupal_get_path('module', 'site_status_message') . '/css/site_status_message.css',
),
),
'#access' => user_access('access content'),
);
}
}
/**
* Implements hook_theme().
*/
function site_status_message_theme($existing, $type, $theme, $path) {
return array(
'site_status_message' => array(
'arguments' => array(
'message' => NULL,
'link' => NULL,
),
'template' => 'site-status-message',
'path' => drupal_get_path('module', 'site_status_message') . '/template',
),
);
}
/**
* Implements hook_preprocess_HOOK().
*
* Preprocess function for the theme template.
*/
function site_status_message_preprocess_site_status_message(&$variables) {
$path = drupal_get_normal_path($variables['link']);
if (variable_get('site_status_message_showlink', '') && drupal_valid_path($path)) {
$readmore = filter_xss(variable_get('site_status_message_readmore', 'Read more'));
$variables['link'] = l($readmore, $path);
}
else {
$variables['link'] = NULL;
}
$variables['message'] = filter_xss($variables['message']);
}
/**
* Helper function of options for which pages the message can display on.
*
* @return array
* Array of page options.
*/
function _site_status_message_get_display_options() {
return array(
'off' => t('Turn off'),
'public' => t('Public-facing site pages'),
'admin' => t('Admin pages'),
'both' => t('Both public-facing site and admin pages'),
);
}
Functions
Name | Description |
---|---|
site_status_message_help | Implements hook_help(). |
site_status_message_menu | Implements hook_page_menu(). |
site_status_message_page_build | Implements hook_page_build(). |
site_status_message_permission | Implements hook_permission(). |
site_status_message_preprocess_site_status_message | Implements hook_preprocess_HOOK(). |
site_status_message_theme | Implements hook_theme(). |
_site_status_message_get_display_options | Helper function of options for which pages the message can display on. |