function ComponentPluginManager::makePathRelativeToLibraryRoot
Same name in this branch
- 11.x core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::makePathRelativeToLibraryRoot()
Same name in other branches
- 10 core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::makePathRelativeToLibraryRoot()
- 10 core/lib/Drupal/Core/Theme/ComponentPluginManager.php \Drupal\Core\Theme\ComponentPluginManager::makePathRelativeToLibraryRoot()
Takes a path and makes it relative to the library provider.
Drupal will take a path relative to the library provider in order to put CSS and JS in the HTML page. Core is the provider for all the auto-generated libraries for the components. This means that in order to add <root>/themes/custom/my_theme/components/my-component/my-component.css in the page, we need to crawl back up from <root>/core first: ../themes/custom/my_theme/components/my-component/my-component.css.
Parameters
string $path: The path to the file.
Return value
string The path relative to the library provider root.
2 calls to ComponentPluginManager::makePathRelativeToLibraryRoot()
- ComponentPluginManager::findAsset in core/
lib/ Drupal/ Core/ Theme/ ComponentPluginManager.php - Finds assets related to the provided metadata file.
- ComponentPluginManager::translateLibraryPaths in core/
lib/ Drupal/ Core/ Theme/ ComponentPluginManager.php - Changes the library paths, so they can be used by the library system.
File
-
core/
lib/ Drupal/ Core/ Theme/ ComponentPluginManager.php, line 468
Class
- ComponentPluginManager
- Defines a plugin manager to deal with components.
Namespace
Drupal\Core\ThemeCode
private function makePathRelativeToLibraryRoot(string $path) : string {
$path_from_root = str_starts_with($path, $this->appRoot) ? substr($path, strlen($this->appRoot) + 1) : $path;
// The library owner is in <root>/core, so we need to go one level up to
// find the app root.
return '../' . $path_from_root;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.