You are here

bootstrap_modal_messages.module in Bootstrap Modal Messages 8

Same filename and directory in other branches
  1. 7 bootstrap_modal_messages.module

Main functions for bootstrap_modal_messages module.

File

bootstrap_modal_messages.module
View source
<?php

/**
 * @file
 * Main functions for bootstrap_modal_messages module.
 */
define('BOOTSTRAP_MODAL_MESSAGES_HEADER', '<h4 class="modal-title">' . t('Messages') . '</h4>');
define('BOOTSTRAP_MODAL_MESSAGES_FOOTER', '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>');

/**
 * Implements hook_help().
 */
function bootstrap_modal_messages_help($path, $arg) {
  switch ($path) {
    case 'admin/help#bootstrap_modal_messages':

      // On the help overview page.
      return '';
    case 'admin/config/user-interface/bootstrap_modal_messages':

      // On the admin settings page.
      return '<p>' . t('This page provides configuration options for bootstrap_modal_messages.module. You can configure how multiple messages are grouped.') . '</p>';
  }
}

/**
 * Implements hook_page_attachments_alter().
 */
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;
}

Functions

Constants

Namesort descending Description
BOOTSTRAP_MODAL_MESSAGES_FOOTER
BOOTSTRAP_MODAL_MESSAGES_HEADER @file Main functions for bootstrap_modal_messages module.