You are here

function modal_page_preprocess_html in Modal 8.3

Same name and namespace in other branches
  1. 8 modal_page.module \modal_page_preprocess_html()
  2. 8.2 modal_page.module \modal_page_preprocess_html()
  3. 5.0.x modal_page.module \modal_page_preprocess_html()
  4. 4.0.x modal_page.module \modal_page_preprocess_html()
  5. 4.1.x modal_page.module \modal_page_preprocess_html()

Implements hook_preprocess_html().

File

./modal_page.module, line 87
Main file for the Modal Page.

Code

function modal_page_preprocess_html(&$variables) {
  $correct_version = modal_page_is_entity_version();
  if (empty($correct_version)) {
    return FALSE;
  }
  $modal_exists = \Drupal::entityQuery('modal_page_modal')
    ->range(0, 1)
    ->execute();
  if (empty($modal_exists)) {
    return FALSE;
  }
  $modal_to_show = \Drupal::service('modal_page.modals')
    ->checkModalToShow();
  if ($modal_to_show) {
    $do_not_show_again = FALSE;
    if (!empty($modal_to_show['do_not_show_again'])) {
      $do_not_show_again = $modal_to_show['do_not_show_again'];
    }
    $title = $modal_to_show['title'];
    $text = $modal_to_show['text'];
    $delay_display = $modal_to_show['delay_display'];
    $modal_size = $modal_to_show['modal_size'];
    $button = $modal_to_show['button'];
    $id = $modal_to_show['id'];
    $open_modal_on_element_click = $modal_to_show['open_modal_on_element_click'];
    $auto_open = $modal_to_show['auto_open'];
    $close_modal_esc_key = $modal_to_show['close_modal_esc_key'];
    $close_modal_clicking_outside = $modal_to_show['close_modal_clicking_outside'];
    $variables['page_top']['slidedown_templates'] = [
      '#theme' => 'modal_page_modal',
      '#do_not_show_again' => $do_not_show_again,
      '#title' => $title,
      '#text' => $text,
      '#delay_display' => $delay_display,
      '#modal_size' => $modal_size,
      '#button' => $button,
      '#id' => $id,
      '#close_modal_esc_key' => $close_modal_esc_key,
      '#close_modal_clicking_outside' => $close_modal_clicking_outside,
    ];
    $variables['#attached']['drupalSettings']['modal_page']['open_modal_on_element_click'] = $open_modal_on_element_click;
    $variables['#attached']['drupalSettings']['modal_page']['auto_open'] = $auto_open;
    if (isset($modal_to_show['do_not_show_again']) && !empty($modal_to_show['do_not_show_again'])) {
      $variables['page_top']['slidedown_templates']['#do_not_show_again'] = $modal_to_show['do_not_show_again'];
    }
  }
}