59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Provides integration with the Inspire tree library.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_library_info_alter().
|
|
*/
|
|
function inspire_tree_library_info_alter(&$libraries, $module) {
|
|
if ($module == 'inspire_tree') {
|
|
// In case that the libraries are included locally, use those instead of the
|
|
// CDN.
|
|
// @see https://www.drupal.org/node/3099614
|
|
$library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
|
|
$current_libraries = [
|
|
'inspire_tree' => 'inspire-tree.min.js',
|
|
'inspire_tree_dom' => 'inspire-tree-dom.min.js',
|
|
'lodash' => 'lodash.min.js',
|
|
];
|
|
foreach ($current_libraries as $current_library_id => $current_library_file) {
|
|
if (isset($libraries[$current_library_id])) {
|
|
$path = $library_file_finder->find($current_library_file);
|
|
if ($path) {
|
|
$libraries[$current_library_id]['js'] = [
|
|
'/' . $path => ['minified' => TRUE]
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Include light/dark mode based on the settings.
|
|
$dom_library = 'inspire_tree_dom';
|
|
if (isset($libraries[$dom_library])) {
|
|
$mode = \Drupal::config('inspire_tree.settings')->get('mode');
|
|
if ($mode !== 'none') {
|
|
$file_name = "inspire-tree-$mode.css";
|
|
$path = $library_file_finder->find($file_name);
|
|
if ($path) {
|
|
$libraries[$dom_library]['css'] = [
|
|
'theme' => [
|
|
'/' . $path => []
|
|
]
|
|
];
|
|
}
|
|
else {
|
|
$version = $libraries[$dom_library]['version'];
|
|
$libraries[$dom_library]['css'] = [
|
|
'theme' => [
|
|
"//cdn.jsdelivr.net/gh/helion3/inspire-tree-dom@$version/dist/$file_name" => []
|
|
]
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|