diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index a95c2ff..fa74923 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -52,7 +52,7 @@ class LibraryDiscoveryParser { * libraries-override behavior where overriding of already overridden paths * required using the full Drupal-root-relative path of the last override. * - * @todo Remove when BC-break is allowed. + * @todo Remove BC layer in Drupal 9.0.0 https://www.drupal.org/node/2852314. * * @var array */ @@ -163,9 +163,12 @@ public function buildByExtension($extension) { } foreach ($library[$type] as $source => $options) { unset($library[$type][$source]); - // Update to the overridden source in libraries-override. - if (!($source = $this->getLatestOverridePath($source, $type, $id, $extension))) { - // Don't bother if the override says 'false'. + // Get the actual overridden path to $source in libraries-override. + $source = $this->getLatestOverridePath($source, $type, $id, $extension); + if (!$source) { + // If $source is false, it means that a libraries-override entry in + // the theme or base theme has specified that the library should be + // removed. Hence this entry should not be processed. continue; } // Allow to omit the options hashmap in YAML declarations. @@ -446,11 +449,11 @@ protected function isValidUri($string) { */ protected function setOverrideValue(array $overrides, $type, $library_name, $extension, $theme_path) { foreach ($overrides as $original => $replacement) { - // $original can either be the last overridden path (also possibly - // using the '@themename' token) or the original library definition path. + // $original can either be the last overridden path or the original + // library definition path. // For BC we check if $original still refers to base-theme overrides. - // @todo Remove when BC-break is allowed. + // @todo Remove BC in Drupal 9.0.0 https://www.drupal.org/node/2852314. if (isset($this->originalLibraryPaths[$original])) { // Here $original actually refers to an overridden path (maybe from a // base theme), so get the actual original path by which the library @@ -471,10 +474,11 @@ protected function setOverrideValue(array $overrides, $type, $library_name, $ext * @param string $theme_path * The theme or base theme. * @param string|false $overriding_asset - * The overriding library asset. + * The overriding library asset or false for asset removal. * - * @return string - * A fully resolved theme asset path relative to the Drupal directory. + * @return string|false + * A fully resolved theme asset path relative to the Drupal directory or + * false if the asset is to be removed. */ protected function resolveThemeAssetPath($theme_path, $overriding_asset) { if ($overriding_asset == FALSE) { @@ -501,9 +505,10 @@ protected function resolveThemeAssetPath($theme_path, $overriding_asset) { * @param string $extension * The extension name. * - * @return string + * @return string|false * The full path to the effective libraries-override asset or $original_path - * if the asset is not overridden. + * if the asset is not overridden. Returns false if the asset is to be + * removed. */ protected function getLatestOverridePath($original_path, $type, $library_name, $extension) { $key = $extension . ':' . $library_name . ':' . $type . ':' . $original_path; @@ -515,8 +520,9 @@ protected function getLatestOverridePath($original_path, $type, $library_name, $ /** * Sets the libraries-override path that applies to the library asset. * - * @param string $new_path - * The Drupal-root-relative path to the overriding library asset. + * @param string|false $new_path + * The Drupal-root-relative path to the overriding library asset or false if + * the asset is to be removed. * @param string $original_path * The original library asset source path. * @param string $type diff --git a/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml b/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml index 3efb45f..6c621ff 100644 --- a/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml +++ b/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml @@ -18,6 +18,10 @@ libraries-override: css: component: assets/vendor/farbtastic/farbtastic.css: css/farbtastic.css + core/normalize: + css: + base: + assets/vendor/normalize-css/normalize.css: css/normalize.css libraries-extend: classy/base: diff --git a/core/modules/system/tests/themes/test_subsubtheme/test_subsubtheme.info.yml b/core/modules/system/tests/themes/test_subsubtheme/test_subsubtheme.info.yml index e254a48..c5f3a25 100644 --- a/core/modules/system/tests/themes/test_subsubtheme/test_subsubtheme.info.yml +++ b/core/modules/system/tests/themes/test_subsubtheme/test_subsubtheme.info.yml @@ -14,3 +14,7 @@ libraries-override: component: # Tests previous behavior of using the last overridden path. /core/modules/system/tests/themes/test_basetheme/css/farbtastic.css: css/subsubtheme-farbtastic.css + core/normalize: + css: + base: + assets/vendor/normalize-css/normalize.css: false diff --git a/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php b/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php index addf6d8..5288d6f 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php @@ -164,11 +164,20 @@ public function testBaseThemeLibrariesOverrideInSubTheme() { * Tests library-override on already overridden libraries. */ public function testLibrariesOverrideOverridden() { + // Activate a sub-theme that doesn't override a library override. + $this->activateTheme('test_subtheme'); + + // Assert that effective libraries override is from the test_subsubtheme. + $this->assertAssetInLibrary('core/modules/system/tests/themes/test_basetheme/css/farbtastic.css', 'core', 'jquery.farbtastic', 'css'); + $this->assertAssetInLibrary('core/modules/system/tests/themes/test_basetheme/css/normalize.css', 'core', 'normalize', 'css'); + // Activate a sub-theme that overrides a library override. $this->activateTheme('test_subsubtheme'); // Assert that effective libraries override is from the test_subsubtheme. $this->assertNoAssetInLibrary('core/modules/system/tests/themes/test_basetheme/css/farbtastic.css', 'core', 'jquery.farbtastic', 'css'); + $this->assertNoAssetInLibrary('core/modules/system/tests/themes/test_basetheme/css/normalize.css', 'core', 'normalize', 'css'); + $this->assertNoAssetInLibrary('core/assets/vendor/normalize-css/normalize.css', 'core', 'normalize', 'css'); $this->assertAssetInLibrary('core/modules/system/tests/themes/test_subsubtheme/css/subsubtheme-farbtastic.css', 'core', 'jquery.farbtastic', 'css'); $this->assertAssetInLibrary('core/modules/system/tests/themes/test_subsubtheme/js/subsubtheme-dialog.js', 'core', 'drupal.dialog', 'js'); }