function ComponentPluginManager::translateLibraryPaths
Same name in this branch
- 10 core/lib/Drupal/Core/Theme/ComponentPluginManager.php \Drupal\Core\Theme\ComponentPluginManager::translateLibraryPaths()
Same name in other branches
- 11.x core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::translateLibraryPaths()
- 11.x core/lib/Drupal/Core/Theme/ComponentPluginManager.php \Drupal\Core\Theme\ComponentPluginManager::translateLibraryPaths()
Changes the library paths, so they can be used by the library system.
We need this so we can let users apply overrides to JS and CSS files with paths relative to the component.
Parameters
array $overrides: The library overrides as provided by the component author.
string $component_directory: The directory for the component.
Return value
array The overrides with the fixed paths.
1 call to ComponentPluginManager::translateLibraryPaths()
- ComponentPluginManager::libraryFromDefinition in core/
modules/ sdc/ src/ ComponentPluginManager.php - Creates the library declaration array from a component definition.
File
-
core/
modules/ sdc/ src/ ComponentPluginManager.php, line 381
Class
- ComponentPluginManager
- Defines a plugin manager to deal with sdc.
Namespace
Drupal\sdcCode
private function translateLibraryPaths(array $overrides, string $component_directory) : array {
// We only alter the keys of the CSS and JS entries.
$altered_overrides = $overrides;
unset($altered_overrides['css'], $altered_overrides['js']);
$css = $overrides['css'] ?? [];
$js = $overrides['js'] ?? [];
foreach ($css as $dir => $css_info) {
foreach ($css_info as $filename => $options) {
if (!UrlHelper::isExternal($filename)) {
$absolute_filename = sprintf('%s%s%s', $component_directory, DIRECTORY_SEPARATOR, $filename);
$altered_filename = $this->makePathRelativeToLibraryRoot($absolute_filename);
$altered_overrides['css'][$dir][$altered_filename] = $options;
}
else {
$altered_overrides['css'][$dir][$filename] = $options;
}
}
}
foreach ($js as $filename => $options) {
if (!UrlHelper::isExternal($filename)) {
$absolute_filename = sprintf('%s%s%s', $component_directory, DIRECTORY_SEPARATOR, $filename);
$altered_filename = $this->makePathRelativeToLibraryRoot($absolute_filename);
$altered_overrides['js'][$altered_filename] = $options;
}
else {
$altered_overrides['js'][$filename] = $options;
}
}
return $altered_overrides;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.