sitewide_alert.module in Sitewide Alert 8
Contains sitewide_alert.module.
File
sitewide_alert.moduleView source
<?php
/**
* @file
* Contains sitewide_alert.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function sitewide_alert_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the sitewide_alert module.
case 'help.page.sitewide_alert':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides ability to display an alert message at the top of all pages.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_page_top().
*/
function sitewide_alert_page_top(array &$page_top) {
// Do not show alert on admin pages if we are not configured to do so.
if (\Drupal::service('router.admin_context')
->isAdminRoute() && !\Drupal::config('sitewide_alert.settings')
->get('show_on_admin')) {
return;
}
$page_top['sitewide_alert'] = [
'#markup' => '<div id="sitewide-alert"></div>',
'#attached' => [
'library' => [
'sitewide_alert/init',
],
'drupalSettings' => [
'sitewideAlert' => [
'refreshInterval' => (\Drupal::config('sitewide_alert.settings')
->get('refresh_interval') ?? 15) * 1000,
'automaticRefresh' => \Drupal::config('sitewide_alert.settings')
->get('automatic_refresh') == 1,
],
],
],
];
}
Functions
Name | Description |
---|---|
sitewide_alert_help | Implements hook_help(). |
sitewide_alert_page_top | Implements hook_page_top(). |