diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index d56126a..f51894c 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -317,12 +317,12 @@ protected function parseLibraryInfo($extension, $path) { * Apply libraries overrides specified for the current active theme. * * @param array $libraries - * The library definition. + * The libraries definitions. * @param string $extension - * The extension in which this library was defined. + * The extension in which these libraries are defined. * * @return array - * The modified library definition. + * The modified libraries definitions. */ protected function applyLibrariesOverrides($libraries, $extension) { $active_theme = $this->themeManager->getActiveTheme(); @@ -356,11 +356,12 @@ protected function applyLibrariesOverrides($libraries, $extension) { $parents = [$component, $value]; $new_parents = [$component, '/' . $theme_path . '/' . $override]; } - // Remove previous component to be overridden. + // Remove previous component to be overridden, but keep the attributes. + $attributes = NestedArray::getValue($libraries[$name], $parents); NestedArray::unsetValue($libraries[$name], $parents); if ($override) { // Replace with an override if specified. - NestedArray::setValue($libraries[$name], $new_parents, []); + NestedArray::setValue($libraries[$name], $new_parents, $attributes); } } } diff --git a/core/modules/system/src/Tests/Asset/LibraryDiscoveryIntegrationTest.php b/core/modules/system/src/Tests/Asset/LibraryDiscoveryIntegrationTest.php index 989f56e..5148824 100644 --- a/core/modules/system/src/Tests/Asset/LibraryDiscoveryIntegrationTest.php +++ b/core/modules/system/src/Tests/Asset/LibraryDiscoveryIntegrationTest.php @@ -73,6 +73,14 @@ public function testLibrariesOverride() { $library = $library_discovery->getLibraryByName('core', 'drupal.dialog'); $this->assertNoAssetInLibraryComponent($library['css'], 'drupal.dialog', 'core/misc/dialog.theme.css'); + // Assert that overridden library component still retains attributes. + $library = $library_discovery->getLibraryByName('core', 'jquery'); + foreach ($library['js'] as $definition) { + if ($definition['data'] == 'core/modules/system/tests/themes/test_theme/js/collapse.js') { + $this->assertEqual($definition['minified'] && $definition['weight'] == -20, 'Previous attributes retained'); + break; + } + } } protected function assertAssetInLibraryComponent($component, $library_name, $asset, $message = NULL) { diff --git a/core/modules/system/tests/themes/test_theme/test_theme.info.yml b/core/modules/system/tests/themes/test_theme/test_theme.info.yml index 9e63615..abfdc65 100644 --- a/core/modules/system/tests/themes/test_theme/test_theme.info.yml +++ b/core/modules/system/tests/themes/test_theme/test_theme.info.yml @@ -24,6 +24,8 @@ libraries-override: classy/base/css/theme/css/layout.css: css/test_theme_layout.css # Remove one particular asset. core/drupal.dialog/css/theme/misc/dialog.theme.css: false + # It works for js as well. + core/jquery/js/assets/vendor/jquery/jquery.min.js: js/collapse.js regions: content: Content left: Left