public function LibraryInfo::alter in Express 8
Alters data for a specific hook_TYPE_alter() implementation.
Parameters
mixed $data: The variable that will be passed to hook_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.
mixed $context1: (optional) An additional variable that is passed by reference.
mixed $context2: (optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.
Overrides AlterInterface::alter
File
- themes/
contrib/ bootstrap/ src/ Plugin/ Alter/ LibraryInfo.php, line 26 - Contains \Drupal\bootstrap\Plugin\Alter\LibraryInfo.
Class
- LibraryInfo
- Implements hook_library_info_alter().
Namespace
Drupal\bootstrap\Plugin\AlterCode
public function alter(&$libraries, &$extension = NULL, &$context2 = NULL) {
$livereload = $this->theme
->livereloadUrl();
// Disable preprocess on all CSS/JS if "livereload" is enabled.
if ($livereload) {
$this
->processLibrary($libraries, function (&$info, &$key, $type) {
if ($type === 'css' || $type === 'js') {
$info['preprocess'] = FALSE;
}
});
}
if ($extension === 'bootstrap') {
// Alter the "livereload.js" placeholder with the correct URL.
if ($livereload) {
$libraries['livereload']['js'][$livereload] = $libraries['livereload']['js']['livereload.js'];
unset($libraries['livereload']['js']['livereload.js']);
}
// Retrieve the theme's CDN provider and assets.
$provider = $this->theme
->getProvider();
$assets = $provider ? $provider
->getAssets() : [];
// Immediately return if there is no provider or assets.
if (!$provider || !$assets) {
return;
}
// Merge the assets into the library info.
$libraries['theme'] = NestedArray::mergeDeepArray([
$assets,
$libraries['theme'],
], TRUE);
// Add a specific version and theme CSS overrides file.
// @todo This should be retrieved by the Provider API.
$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)) {
// Since this uses a relative path to the ancestor from DRUPAL_ROOT,
// we must prepend the entire path with forward slash (/) so it
// doesn't prepend the active theme's path.
$overrides = "/{$overrides}";
// The overrides file must also be stored in the "base" category so
// it isn't added after any potential sub-theme's "theme" category.
// There's no weight, so it will be added after the provider's assets.
// @see https://www.drupal.org/node/2770613
$libraries['theme']['css']['base'][$overrides] = [];
break;
}
}
}
elseif ($extension === 'core') {
// Replace core dialog/jQuery UI implementations with Bootstrap Modals.
if ($this->theme
->getSetting('modal_enabled')) {
$libraries['drupal.dialog']['override'] = 'bootstrap/drupal.dialog';
$libraries['drupal.dialog.ajax']['override'] = 'bootstrap/drupal.dialog.ajax';
}
}
}