You are here

function ajax_loader_library_info_alter in Ajax loader 8

Implements hook_library_info_alter().

File

./ajax_loader.module, line 19

Code

function ajax_loader_library_info_alter(&$libraries, $module) {
  if ($module == 'ajax_loader') {

    /** @var \Drupal\ajax_loader\ThrobberManagerInterface $throbber_manager */
    $throbber_manager = Drupal::service('ajax_loader.throbber_manager');

    // Add all css for throbber plugins on admin page.
    foreach ($throbber_manager
      ->loadAllThrobberInstances() as $throbber) {

      /** @var \Drupal\ajax_loader\ThrobberPluginInterface $throbber */
      if ($css_file = $throbber
        ->getCssFile()) {
        $libraries['ajax_loader.admin']['css']['theme'][$css_file] = [];
      }
    }
    $settings = \Drupal::config('ajax_loader.settings');
    if ($settings
      ->get('throbber') && isset($libraries['ajax_loader.throbber'])) {

      // Add css for chosen throbber.
      $throbber = $throbber_manager
        ->loadThrobberInstance($settings
        ->get('throbber'));
      if ($css_file = $throbber
        ->getCssFile()) {
        $libraries['ajax_loader.throbber']['css']['theme'][$css_file] = [];
      }
    }
  }
}