class LibraryInfo in Express 8
Implements hook_library_info_alter().
Plugin annotation
@BootstrapAlter("library_info");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\bootstrap\Plugin\PluginBase
- class \Drupal\bootstrap\Plugin\Alter\LibraryInfo implements AlterInterface
- class \Drupal\bootstrap\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LibraryInfo
File
- themes/
contrib/ bootstrap/ src/ Plugin/ Alter/ LibraryInfo.php, line 21 - Contains \Drupal\bootstrap\Plugin\Alter\LibraryInfo.
Namespace
Drupal\bootstrap\Plugin\AlterView source
class LibraryInfo extends PluginBase implements AlterInterface {
/**
* {@inheritdoc}
*/
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';
}
}
}
/**
* Processes library definitions.
*
* @param array $libraries
* The libraries array, passed by reference.
* @param callable $callback
* The callback to perform processing on the library.
*/
public function processLibrary(&$libraries, callable $callback) {
foreach ($libraries as &$library) {
foreach ($library as $type => $definition) {
if (is_array($definition)) {
$modified = [];
// CSS needs special handling since it contains grouping.
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;
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LibraryInfo:: |
public | function |
Alters data for a specific hook_TYPE_alter() implementation. Overrides AlterInterface:: |
|
LibraryInfo:: |
public | function | Processes library definitions. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
protected | property | The currently set theme object. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |