diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscovery.php b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php index 422356a..bf80a30 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscovery.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php @@ -79,6 +79,7 @@ public function getLibraryByName($extension, $name) { $extension = $this->getLibrariesByExtension($extension); if (isset($extension[$name])) { // Handle libraries that are marked for override or removal. + // @see \Drupal\Core\Asset\LibraryDiscoveryParser::applyLibrariesOverrides() if (isset($extension[$name]['override'])) { if ($extension[$name]['override']) { list($new_extension, $new_name) = explode('/', $extension[$name]['override']); diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 5c97820..d56126a 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -87,8 +87,7 @@ public function buildByExtension($extension) { $path = $this->drupalGetPath($extension_type, $extension); } - $libraries = $this->parseLibraryInfo($extension, $path); - $this->applyLibrariesOverrides($libraries, $extension, $path); + $libraries = $this->applyLibrariesOverrides($this->parseLibraryInfo($extension, $path), $extension); foreach ($libraries as $id => &$library) { if (!isset($library['js']) && !isset($library['css']) && !isset($library['drupalSettings'])) { @@ -321,21 +320,22 @@ protected function parseLibraryInfo($extension, $path) { * The library definition. * @param string $extension * The extension in which this library was defined. - * @param string $path - * The root path of the extension. * * @return array * The modified library definition. */ - protected function applyLibrariesOverrides(&$libraries, $extension, $path) { - $libraries_overrides = $this->themeManager->getActiveTheme()->getLibrariesOverride(); - $theme_path = $this->themeManager->getActiveTheme()->getPath(); + protected function applyLibrariesOverrides($libraries, $extension) { + $active_theme = $this->themeManager->getActiveTheme(); + $libraries_overrides = $active_theme->getLibrariesOverride(); + $theme_path = $active_theme->getPath(); foreach ($libraries as $name => $library) { // Process libraries overrides. foreach ($libraries_overrides as $item => $override) { // Active theme defines an override for this library. if ($item === "$extension/$name") { - // The whole library. + // The whole library. Use the override key to specify that this + // library will be overridden when it is called. + // @see \Drupal\Core\Asset\LibraryDiscovery::getLibraryByName() if ($override) { $libraries[$name]['override'] = $override; } @@ -365,6 +365,7 @@ protected function applyLibrariesOverrides(&$libraries, $extension, $path) { } } } + return $libraries; } /** diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 4fa0db4..9c3dbfa 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -73,6 +73,15 @@ protected function setUp() { $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->themeManager = $this->getMock('Drupal\Core\Theme\ThemeManagerInterface'); + $mock_active_theme = $this->getMockBuilder('Drupal\Core\Theme\ActiveTheme') + ->disableOriginalConstructor() + ->getMock(); + $mock_active_theme->expects($this->any()) + ->method('getLibrariesOverride') + ->willReturn([]); + $this->themeManager->expects($this->any()) + ->method('getActiveTheme') + ->willReturn($mock_active_theme); $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->root, $this->moduleHandler, $this->themeManager); }