You are here

function select2_library_info_alter in Select 2 8

Implements hook_library_info_alter().

File

./select2.module, line 11
This is the Select2 module.

Code

function select2_library_info_alter(&$libraries, $extension) {
  if ($extension === 'select2') {
    $libraries_path = 'libraries/select2';
    if (\Drupal::hasService('library.libraries_directory_file_finder')) {
      $libraries_path = \Drupal::service('library.libraries_directory_file_finder')
        ->find('select2');
    }
    elseif (function_exists('libraries_get_path')) {
      $libraries_path = libraries_get_path('select2');
    }
    $libraries['select2.min']['js'] = [
      '/' . $libraries_path . '/dist/js/select2.min.js' => [
        'minified' => TRUE,
      ],
    ];
    $libraries['select2.min']['css']['component'] = [
      '/' . $libraries_path . '/dist/css/select2.min.css' => [],
    ];
    foreach (\Drupal::languageManager()
      ->getLanguages() as $language) {
      if (file_exists($libraries_path . '/dist/js/i18n/' . $language
        ->getId() . '.js')) {
        $libraries['select2.i18n.' . $language
          ->getId()] = [
          'js' => [
            '/' . $libraries_path . '/dist/js/i18n/' . $language
              ->getId() . '.js' => [
              'minified' => TRUE,
            ],
          ],
          'dependencies' => [
            'select2/select2',
          ],
        ];
      }
    }
  }
  $module_path = \Drupal::moduleHandler()
    ->getModule('select2')
    ->getPath();
  if (file_exists("{$module_path}/css/select2.{$extension}.css")) {
    $libraries['select2.theme'] = [
      'css' => [
        'component' => [
          "/{$module_path}/css/select2.{$extension}.css" => [],
        ],
      ],
    ];
  }
}