function LibraryDiscoveryParser::setOverrideValue
Same name in other branches
- 9 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::setOverrideValue()
- 10 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::setOverrideValue()
- 11.x core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::setOverrideValue()
Overrides the specified library asset.
Parameters
array $library: The containing library definition.
array $sub_key: An array containing the sub-keys specifying the library asset, e.g.
[
'js',
];
or
[
'css',
'component',
];
array $overrides: Specifies the overrides, this is an array where the key is the asset to be overridden while the value is overriding asset.
1 call to LibraryDiscoveryParser::setOverrideValue()
- LibraryDiscoveryParser::applyLibrariesOverride in core/
lib/ Drupal/ Core/ Asset/ LibraryDiscoveryParser.php - Apply libraries overrides specified for the current active theme.
File
-
core/
lib/ Drupal/ Core/ Asset/ LibraryDiscoveryParser.php, line 471
Class
- LibraryDiscoveryParser
- Parses library files to get extension data.
Namespace
Drupal\Core\AssetCode
protected function setOverrideValue(array &$library, array $sub_key, array $overrides, $theme_path) {
foreach ($overrides as $original => $replacement) {
// Get the attributes of the asset to be overridden. If the key does
// not exist, then throw an exception.
$key_exists = NULL;
$parents = array_merge($sub_key, [
$original,
]);
// Save the attributes of the library asset to be overridden.
$attributes = NestedArray::getValue($library, $parents, $key_exists);
if ($key_exists) {
// Remove asset to be overridden.
NestedArray::unsetValue($library, $parents);
// No need to replace if FALSE is specified, since that is a removal.
if ($replacement) {
// Ensure the replacement path is relative to drupal root.
$replacement = $this->resolveThemeAssetPath($theme_path, $replacement);
$new_parents = array_merge($sub_key, [
$replacement,
]);
// Replace with an override if specified.
NestedArray::setValue($library, $new_parents, $attributes);
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.