function site_banner_page_top in Site Banner 8
Same name and namespace in other branches
- 2.0.x site_banner.module \site_banner_page_top()
- 1.0.x site_banner.module \site_banner_page_top()
Implements hook_page_top().
File
- ./
site_banner.module, line 27 - Site banner module.
Code
function site_banner_page_top(array &$page_top) {
$config = \Drupal::configFactory()
->get('site_banner.settings');
$banner_text = $config
->get('site_banner_text');
$status = $config
->get('status') ?? FALSE;
$header = $config
->get('show_header') ?? FALSE;
$footer = $config
->get('show_footer') ?? FALSE;
$backgroundColor = $config
->get('site_banner_color') ?? '#FFFFFF';
$startDate = $config
->get('site_banner_start_date');
$endDate = $config
->get('site_banner_end_date');
$isStart = TRUE;
$isEnd = FALSE;
if ($startDate) {
$startDateTime = new DrupalDateTime($startDate);
$timeDiff = $startDateTime
->getTimestamp() - (new DrupalDateTime('now'))
->getTimestamp();
$isStart = $timeDiff < 0;
}
if ($endDate) {
$endDateTime = new DrupalDateTime($endDate);
$timeDiff = $endDateTime
->getTimestamp() - (new DrupalDateTime('now'))
->getTimestamp();
$isEnd = $timeDiff < 0;
}
if ($status && !empty($banner_text) && $isStart && !$isEnd && ($header || $footer)) {
$headerTag = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'id' => 'site-banner-header-banner',
'class' => [
'toolbar',
'clearfix',
'toolbar-processed',
'overlay-displace-top',
],
'style' => 'padding-bottom: 5px; background-color:' . $backgroundColor,
';',
],
'#value' => \Drupal\Core\Render\Markup::create($banner_text),
];
$footerTag = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'id' => 'site-banner-footer-banner',
'class' => [
'toolbar',
'clearfix',
'toolbar-processed',
'overlay-displace-top',
],
'style' => 'padding-bottom: 5px; background-color:' . $backgroundColor,
';',
],
'#value' => $banner_text,
'#weight' => -100,
];
if ($header) {
$page_top['site_banner'][] = $headerTag;
}
if ($footer) {
$page_top['site_banner'][] = $footerTag;
}
}
}