You are here

function ajax_loader_page_attachments in Ajax loader 8

Implements hook_page_attachments().

File

./ajax_loader.module, line 46

Code

function ajax_loader_page_attachments(array &$page) {

  /** @var \Drupal\ajax_loader\ThrobberManagerInterface $throbber_manager */
  $settings = \Drupal::config('ajax_loader.settings');
  $throbber_manager = Drupal::service('ajax_loader.throbber_manager');
  $throbber = $settings
    ->get('throbber');
  if ($throbber_manager
    ->getDefinition($throbber, FALSE) && $throbber_manager
    ->RouteIsApplicable()) {

    /** @var \Drupal\ajax_loader\ThrobberPluginInterface $throbber */
    $throbber = $throbber_manager
      ->loadThrobberInstance($settings
      ->get('throbber'));
    $settings = [
      'markup' => $throbber
        ->getMarkup(),
      'hideAjaxMessage' => $settings
        ->get('hide_ajax_message'),
      'alwaysFullscreen' => $settings
        ->get('always_fullscreen'),
      'throbberPosition' => $settings
        ->get('throbber_position'),
    ];
    $page['#attached']['drupalSettings']['ajaxLoader'] = $settings;
    $page['#attached']['library'][] = 'ajax_loader/ajax_loader.throbber';
  }
}