You are here

function page_load_progress_page_attachments in Page Load Progress 8

Implements hook_page_attachments().

File

./page_load_progress.module, line 57
Allows to attach page_load_progress assets to all pages.

Code

function page_load_progress_page_attachments(array &$attachments) {

  // Load module configuration.
  $config = \Drupal::config('page_load_progress.settings');
  if (\Drupal::currentUser()
    ->hasPermission('use page load progress') && !strpos(\Drupal::service('path.current')
    ->getPath(), 'admin/structure/views/') && evaluate_visibility_conditions($config)) {

    // Unconditionally attach assets to the page.
    $attachments['#attached']['library'][] = 'page_load_progress/page_load_progress';

    // Attach config settings.
    $attachments['#attached']['drupalSettings']['page_load_progress'] = [
      'delay' => $config
        ->get('page_load_progress_time'),
      'elements' => $config
        ->get('page_load_progress_elements'),
      'internal_links' => $config
        ->get('page_load_progress_internal_links'),
      'esc_key' => $config
        ->get('page_load_progress_esc_key'),
    ];
  }
}