You are here

function modal_page_page_attachments in Modal 8.2

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

Implements hook_page_attachments().

File

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

Code

function modal_page_page_attachments(array &$attachments) {
  $correct_version = modal_page_is_entity_version();
  if (empty($correct_version)) {
    $roles = \Drupal::currentUser()
      ->getRoles();
    if (in_array("administrator", $roles)) {
      $messenger = \Drupal::messenger();
      $messenger
        ->addWarning(t('Modal Page use Entity and Exists pending update(s). Please run /update.php'));
    }
    return FALSE;
  }
  $config = \Drupal::config('modal_page.settings');
  $load_modal_page_bootstrap = TRUE;
  if (!empty($config
    ->get('no_modal_page_external_js'))) {
    $load_modal_page_bootstrap = FALSE;
  }
  $modal_exists = \Drupal::entityQuery('modal_page_modal')
    ->range(0, 1)
    ->execute();
  if (!empty($modal_exists)) {

    // Load Modal Page Library.
    $attachments['#attached']['library'][] = 'modal_page/modal-page';

    // Load Bootstrap Library only if necessary.
    if ($load_modal_page_bootstrap) {
      $attachments['#attached']['library'][] = 'modal_page/modal-page-bootstrap';
    }
  }
}