You are here

function modal_page_preprocess_html in Modal 4.1.x

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

Implements hook_preprocess_html().

File

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

Code

function modal_page_preprocess_html(&$variables) {

  // Get Modals to show on this page.
  $modals = \Drupal::service('modal_page.modals')
    ->getModalsToShow();
  if (empty($modals)) {
    return FALSE;
  }
  foreach ($modals as $modal) {
    $modalOptions = \Drupal::service('modal_page.helper')
      ->getModalOptions($modal);
    $variables['page_top']['slidedown_templates'][] = [
      '#theme' => 'modal_page_modal',
      '#do_not_show_again' => $modal
        ->getDontShowAgainLabel(),
      '#title' => $modal
        ->label(),
      '#display_title' => $modal
        ->getDisplayTitle(),
      '#text' => $modal
        ->getBody(),
      '#delay_display' => $modal
        ->getDelayDisplay(),
      '#modal_size' => $modal
        ->getModalSize(),
      '#button' => $modal
        ->getOkLabelButton(),
      '#id' => $modal
        ->id(),
      '#close_modal_esc_key' => $modal
        ->getCloseModalEscKey(),
      '#close_modal_clicking_outside' => $modal
        ->getCloseModalClickingOutside(),
      '#modal_header_classes' => $modal
        ->getHeaderClass(),
      '#modal_footer_classes' => $modal
        ->getFooterClass(),
      '#enable_modal_header' => $modal
        ->getEnableModalHeader(),
      '#enable_modal_footer' => $modal
        ->getEnableModalFooter(),
      '#display_button_x_close' => $modal
        ->getDisplayButtonXclose(),
      '#top_right_button_label' => $modal
        ->getTopRightButtonLabel(),
      '#top_right_button_class' => $modal
        ->getTopRightButtonClass(),
      '#open_modal_on_element_click' => $modal
        ->getOpenModalOnElementClick(),
      '#auto_open' => $modal
        ->getAutoOpen(),
      '#modal_class' => $modal
        ->getModalClass(),
      '#enable_left_button' => $modal
        ->getEnableLeftButton(),
      '#left_label_button' => $modal
        ->getLeftLabelButton(),
      '#enable_right_button' => $modal
        ->getEnableRightButton(),
      '#ok_button_class' => $modal
        ->getOkButtonClass(),
      '#left_button_class' => $modal
        ->getLeftButtonClass(),
      '#modal_options' => $modalOptions,
      '#id_label' => $modal
        ->id() . '_label',
      '#id_desc' => $modal
        ->id() . '_desc',
      '#enable_redirect_link' => $modal
        ->getEnableRedirectLink(),
      '#redirect_link' => $modal
        ->getRedirectLink(),
    ];
    if (!empty($modal
      ->getEnableDontShowAgainOption())) {
      $variables['page_top']['slidedown_templates']['#do_not_show_again'] = $modal
        ->getEnableDontShowAgainOption();
    }

    // Drupal Settings.
    $verifyLoadBootstrapAutomatically = \Drupal::config('modal_page.settings')
      ->get('verify_load_bootstrap_automatically');
    $variables['#attached']['drupalSettings']['modal_page']['verify_load_bootstrap_automatically'] = $verifyLoadBootstrapAutomatically;
  }
}