This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
select2.module
67 lines (62 loc) · 2.09 KB
/
select2.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @file
* This is the Select2 module.
*/
/**
* Implements hook_library_info_alter().
*/
function select2_library_info_alter(array &$libraries, string $extension): void {
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" => [],
],
],
];
}
}
/**
* Implements hook_library_info_build().
*/
function select2_library_info_build(): array {
$libraries = [];
foreach (\Drupal::languageManager()->getLanguages() as $language) {
if (file_exists('libraries/select2/dist/js/i18n/' . $language->getId() . '.js')) {
$libraries['select2.i18n.' . $language->getId()] = [
'js' => [
'/libraries/select2/dist/js/i18n/' . $language->getId() . '.js' => ['minified' => TRUE],
],
'dependencies' => [
'select2/select2',
],
];
}
}
return $libraries;
}