LibraryInfo.php in Express 8
File
themes/contrib/bootstrap/src/Plugin/Alter/LibraryInfo.php
View source
<?php
namespace Drupal\bootstrap\Plugin\Alter;
use Drupal\bootstrap\Annotation\BootstrapAlter;
use Drupal\bootstrap\Bootstrap;
use Drupal\bootstrap\Plugin\PluginBase;
use Drupal\Component\Utility\NestedArray;
class LibraryInfo extends PluginBase implements AlterInterface {
public function alter(&$libraries, &$extension = NULL, &$context2 = NULL) {
$livereload = $this->theme
->livereloadUrl();
if ($livereload) {
$this
->processLibrary($libraries, function (&$info, &$key, $type) {
if ($type === 'css' || $type === 'js') {
$info['preprocess'] = FALSE;
}
});
}
if ($extension === 'bootstrap') {
if ($livereload) {
$libraries['livereload']['js'][$livereload] = $libraries['livereload']['js']['livereload.js'];
unset($libraries['livereload']['js']['livereload.js']);
}
$provider = $this->theme
->getProvider();
$assets = $provider ? $provider
->getAssets() : [];
if (!$provider || !$assets) {
return;
}
$libraries['theme'] = NestedArray::mergeDeepArray([
$assets,
$libraries['theme'],
], TRUE);
$version = $this->theme
->getSetting('cdn_' . $provider
->getPluginId() . '_version') ?: Bootstrap::FRAMEWORK_VERSION;
$libraries['theme']['version'] = $version;
$provider_theme = $this->theme
->getSetting('cdn_' . $provider
->getPluginId() . '_theme') ?: 'bootstrap';
$provider_theme = $provider_theme === 'bootstrap' || $provider_theme === 'bootstrap_theme' ? '' : "-{$provider_theme}";
foreach ($this->theme
->getAncestry(TRUE) as $ancestor) {
$overrides = $ancestor
->getPath() . "/css/{$version}/overrides{$provider_theme}.min.css";
if (file_exists($overrides)) {
$overrides = "/{$overrides}";
$libraries['theme']['css']['base'][$overrides] = [];
break;
}
}
}
elseif ($extension === 'core') {
if ($this->theme
->getSetting('modal_enabled')) {
$libraries['drupal.dialog']['override'] = 'bootstrap/drupal.dialog';
$libraries['drupal.dialog.ajax']['override'] = 'bootstrap/drupal.dialog.ajax';
}
}
}
public function processLibrary(&$libraries, callable $callback) {
foreach ($libraries as &$library) {
foreach ($library as $type => $definition) {
if (is_array($definition)) {
$modified = [];
if ($type === 'css') {
foreach ($definition as $group => $files) {
foreach ($files as $key => $info) {
call_user_func_array($callback, [
&$info,
&$key,
$type,
]);
$modified[$group][$key] = $info;
}
}
}
else {
foreach ($definition as $key => $info) {
call_user_func_array($callback, [
&$info,
&$key,
$type,
]);
$modified[$key] = $info;
}
}
$library[$type] = $modified;
}
}
}
}
}