jq_ui-8.x-1.8/jquery_ui/jquery_ui.module

jquery_ui/jquery_ui.module
<?php

/**
 * @file
 * Contains jquery_ui.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function jquery_ui_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.jquery_ui':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Drupal 8 includes jQuery UI in core, however it is no longer actively maintained and has been marked deprecated. This module provides the jQuery UI asset library for any themes and modules that require it.') . '</p>';
      $output .= '<p>' . t('For more information about the deprecation of jQuery UI, see this <a href=":change-record">change record</a>', [':change-record' => 'https://www.drupal.org/node/3067969']) . '</p>';
      $output .= '<p>' . t('Visit the <a href=":project_link">jQuery UI project page</a> on Drupal.org for more information about this module.', [':project_link' => 'https://www.drupal.org/project/jquery_ui']) . '</p>';

      return $output;
  }
}

/**
 * Implements hook_library_info_alter().
 *
 * Declare libraries on behalf of sub-modules.
 */
function jquery_ui_library_info_alter(array &$libraries, string $module): void {
  $data = &drupal_static(__FUNCTION__, []);
  if (empty($data)) {
    $data['libraries'] = json_decode(file_get_contents(__DIR__ . '/jquery_ui.libraries.data.json'), TRUE, 512, JSON_THROW_ON_ERROR);
    $data['path'] = \Drupal::service('module_handler')->getModule('jquery_ui')->getPath();
  }

  if (array_key_exists($module, $data['libraries'])) {
    $module_libraries = $data['libraries'][$module];
    foreach ($module_libraries as &$definition) {
      // Set some defaults.
      $definition += ['css' => [], 'js' => []];
      foreach ($definition['css'] as $bem => $files) {
        $definition['css'][$bem] = array_combine(array_map(function ($path) use ($data) {
          return "/$data[path]/$path";
        }, array_keys($files)), $files);
      }
      $definition['js'] = array_combine(array_map(function ($path) use ($data) {
        return "/$data[path]/$path";
      }, array_keys($definition['js'])), $definition['js']);
    }
    $libraries = array_merge($libraries, $module_libraries);
  }

  if ($module === 'jquery_ui_datepicker' && isset($libraries['datepicker']) && \Drupal::moduleHandler()->moduleExists('locale')) {
    $libraries['datepicker']['dependencies'][] = 'jquery_ui/locale';
    $libraries['datepicker']['drupalSettings']['jquery']['ui']['datepicker'] = [
      'isRTL' => NULL,
      'firstDay' => NULL,
      'langCode' => 'drupal-locale',
    ];
  }

  // Replace Core jQuery UI files with ours.
  if ($module === 'core') {
    foreach ($libraries as &$library) {
      if (!empty($library['js'])) {
        _jquery_ui_replace_core_library_assets($library['js']);
      }

      if (!empty($library['css'])) {
        foreach ($library['css'] as &$core_css_files) {
          _jquery_ui_replace_core_library_assets($core_css_files);
        }
        unset($core_css_files);
      }
    }
  }
}

/**
 * Replace core jQuery UI library assets with jquery_ui module assets.
 *
 * This replaces the actual files in the core libraries instead of adding a
 * dependency to the jquery_ui libraries. Adding a dependency to the jquery_ui
 * library can cause unwanted behaviors since it will affect the resolved
 * dependency weight of the core library.
 *
 * The weights defined in jquery_ui.libraries.data.json must match the file
 * weights of the core libraries so that file ordering is correct when using
 * aggregation.
 *
 * @param array $assets
 *   The library assets.
 */
function _jquery_ui_replace_core_library_assets(array &$assets): void {
  $contrib_replace_base_path = ltrim(\Drupal::service('extension.list.module')->getPath('jquery_ui') . '/assets/vendor/jquery.ui', '/');
  $core_library_dir = 'assets/vendor/jquery.ui';

  $asset_keys = array_keys($assets);
  $changed = FALSE;
  foreach ($asset_keys as &$asset_path) {
    if (str_starts_with($asset_path, $core_library_dir)) {
      $ui_asset_path = preg_replace('@^' . preg_quote($core_library_dir, '@') . '/@', '', $asset_path);
      $contrib_asset_path = "{$contrib_replace_base_path}/{$ui_asset_path}";
      if (file_exists($contrib_asset_path)) {
        $asset_path = '/' . $contrib_asset_path;
        $changed = TRUE;
      }
    }
  }
  unset($asset_path);

  if ($changed) {
    $assets = array_combine($asset_keys, array_values($assets));
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc