function bootstrap_modal_messages_page_attachments_alter in Bootstrap Modal Messages 8
Implements hook_page_attachments_alter().
File
- ./
bootstrap_modal_messages.module, line 30 - Main functions for bootstrap_modal_messages module.
Code
function bootstrap_modal_messages_page_attachments_alter(array &$page) {
$ignore_admin = \Drupal::config('bootstrap_modal_messages.settings')
->get('bootstrap_modal_messages_ignore_admin');
if ($ignore_admin && \Drupal::service('router.admin_context')
->isAdminRoute()) {
return;
}
// Load configuration object.
$config = \Drupal::config('bootstrap_modal_messages.settings');
// Filter user input on textareas.
$title_text = BOOTSTRAP_MODAL_MESSAGES_HEADER;
$title = $config
->get('bootstrap_modal_messages_title');
if (isset($title['value']) && isset($title['format']) && $title['value'] != '') {
$title_text = check_markup($title['value'], $title['format']);
}
// Default footer text.
$footer_text = BOOTSTRAP_MODAL_MESSAGES_FOOTER;
$footer = $config
->get('bootstrap_modal_messages_footer_html');
if (isset($footer['value']) && isset($footer['format']) && $footer['value'] != '') {
$footer_text = check_markup($footer['value'], $footer['format']);
}
// Filter user input on textareas.
$controls_text = '';
$controls = $config
->get('bootstrap_modal_messages_controls_html');
if (isset($controls['value']) && isset($controls['format'])) {
$controls_text = check_markup($controls['value'], $controls['format']);
}
$js_settings = array(
'selector' => $config
->get('bootstrap_modal_messages_selector'),
'show_header' => $config
->get('bootstrap_modal_messages_show_header'),
'title' => $title_text,
'header_close' => $config
->get('bootstrap_modal_messages_header_close'),
'show_footer' => $config
->get('bootstrap_modal_messages_show_footer'),
'footer_html' => $footer_text,
'multiple' => $config
->get('bootstrap_modal_messages_multiple'),
'show_onload' => $config
->get('bootstrap_modal_messages_show_onload'),
'onload_expiration' => $config
->get('bootstrap_modal_messages_onload_expiration'),
'show_controls' => $config
->get('bootstrap_modal_messages_show_controls'),
'controls_html' => $controls_text,
);
// Override setting with permission.
if (!\Drupal::currentUser()
->hasPermission('view bootstrap modal messages controls')) {
$js_settings['show_controls'] = 0;
}
$page['#attached']['library'][] = 'bootstrap_modal_messages/bootstrap-modal-messages';
$page['#attached']['drupalSettings']['bootstrap_modal_messages'] = $js_settings;
}