View source
<?php
use Drupal\Core\Routing\RouteMatchInterface;
function ajax_loader_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.ajax_loader':
$output = file_get_contents(drupal_get_path('module', 'ajax_loader') . '/README.txt');
return '<pre>' . $output . '</pre>';
}
}
function ajax_loader_library_info_alter(&$libraries, $module) {
if ($module == 'ajax_loader') {
$throbber_manager = Drupal::service('ajax_loader.throbber_manager');
foreach ($throbber_manager
->loadAllThrobberInstances() as $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'])) {
$throbber = $throbber_manager
->loadThrobberInstance($settings
->get('throbber'));
if ($css_file = $throbber
->getCssFile()) {
$libraries['ajax_loader.throbber']['css']['theme'][$css_file] = [];
}
}
}
}
function ajax_loader_page_attachments(array &$page) {
$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()) {
$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';
}
}