select2-8.x-1.11/select2.module
select2.module
<?php
/**
* @file
* This is the Select2 module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function select2_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the select2 module.
case 'help.page.select2':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This module provides a render element (for usage in forms) and two field widgets.') . '</p>';
$output .= '<p>' . t('One for simple select fields and another for entity reference fields.') . '</p>';
return $output;
}
}
/**
* Implements hook_library_info_alter().
*/
function select2_library_info_alter(array &$libraries, string $extension): void {
if ($extension === 'select2') {
$libraries_path = \Drupal::service('library.libraries_directory_file_finder')->find('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;
}
