From 05d87619c305de7c20a9d2394dae66b02ff915df Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 9 Apr 2022 07:30:39 +0200 Subject: [PATCH] Issue #3258931 by nod_, hooroomoo, xjm, catch, effulgentsia, Wim Leers: Deprecate backbone and tag it internal --- core/core.libraries.yml | 20 +++++++++- core/lib/Drupal/Core/Render/theme.api.php | 2 +- core/modules/ckeditor/ckeditor.libraries.yml | 2 +- .../contextual/contextual.libraries.yml | 6 ++- .../modules/quickedit/quickedit.libraries.yml | 2 +- .../modules/theme_test/theme_test.module | 2 +- .../src/Functional/Theme/ThemeInfoTest.php | 2 +- core/modules/toolbar/toolbar.libraries.yml | 3 +- core/modules/tour/tour.libraries.yml | 3 +- core/scripts/js/vendor-update.js | 7 +++- .../Core/Asset/AttachedAssetsTest.php | 4 +- .../Core/Asset/DeprecatedBackboneTest.php | 38 +++++++++++++++++++ 12 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 core/tests/Drupal/KernelTests/Core/Asset/DeprecatedBackboneTest.php diff --git a/core/core.libraries.yml b/core/core.libraries.yml index 21e7989125ed..e79d13db3226 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -1,6 +1,24 @@ # All libraries are defined in alphabetical order. backbone: + remote: https://github.com/jashkenas/backbone + version: "1.4.0" + license: + name: MIT + url: https://raw.githubusercontent.com/jashkenas/backbone/1.4.0/LICENSE + gpl-compatible: true + js: + assets/vendor/backbone/backbone-min.js: { weight: -19, minified: true } + dependencies: + - core/underscore + deprecated: The %library_id% asset library is deprecated in Drupal 9.4.0 and will be removed in Drupal 10.0.0. + +internal.backbone: + # Internal library. Do not depend on it outside core nor add new core usage. + # The library will be removed as soon as the following issues are fixed: + # - https://www.drupal.org/project/drupal/issues/3203920 + # - https://www.drupal.org/project/drupal/issues/3204011 + # - https://www.drupal.org/project/drupal/issues/3204015 remote: https://github.com/jashkenas/backbone version: "1.4.0" license: @@ -1085,7 +1103,7 @@ underscore: deprecated: The %library_id% asset library is deprecated in Drupal 9.4.0 and will be removed in Drupal 10.0.0. internal.underscore: - # Internal library, do not depend on it. + # Internal library. Do not depend on it outside core nor add new core usage. # The library will be removed as soon as the following issues are fixed: # - https://www.drupal.org/project/drupal/issues/3270395 # - https://www.drupal.org/project/drupal/issues/3203920 diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index ec254499ba25..dccd37777884 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -844,7 +844,7 @@ function hook_library_info_build() { // Add a library whose information changes depending on certain conditions. $libraries['mymodule.zombie'] = [ 'dependencies' => [ - 'core/backbone', + 'core/once', ], ]; if (Drupal::moduleHandler()->moduleExists('minifyzombies')) { diff --git a/core/modules/ckeditor/ckeditor.libraries.yml b/core/modules/ckeditor/ckeditor.libraries.yml index 48bb5e473576..7c6fc2f933b5 100644 --- a/core/modules/ckeditor/ckeditor.libraries.yml +++ b/core/modules/ckeditor/ckeditor.libraries.yml @@ -50,7 +50,7 @@ drupal.ckeditor.admin: - core/drupal - core/drupalSettings - core/once - - core/backbone + - core/internal.backbone - core/drupal.dialog - core/drupal.announce - core/ckeditor diff --git a/core/modules/contextual/contextual.libraries.yml b/core/modules/contextual/contextual.libraries.yml index 3a5918f7e155..0a0117be00b8 100644 --- a/core/modules/contextual/contextual.libraries.yml +++ b/core/modules/contextual/contextual.libraries.yml @@ -22,7 +22,8 @@ drupal.contextual-links: - core/drupal - core/drupal.ajax - core/drupalSettings - - core/backbone + # @todo Remove this in https://www.drupal.org/project/drupal/issues/3203920 + - core/internal.backbone - core/modernizr - core/once @@ -41,7 +42,8 @@ drupal.contextual-toolbar: dependencies: - core/jquery - core/drupal - - core/backbone + # @todo Remove this in https://www.drupal.org/project/drupal/issues/3203920 + - core/internal.backbone - core/once - core/drupal.tabbingmanager - core/drupal.announce diff --git a/core/modules/quickedit/quickedit.libraries.yml b/core/modules/quickedit/quickedit.libraries.yml index 60cb2f6d4bbc..cb5813927a0d 100644 --- a/core/modules/quickedit/quickedit.libraries.yml +++ b/core/modules/quickedit/quickedit.libraries.yml @@ -30,7 +30,7 @@ quickedit: - core/jquery - core/once - core/internal.underscore - - core/backbone + - core/internal.backbone - core/jquery.form - core/drupal - core/drupal.displace diff --git a/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module index 620a19639dfd..2e88a4abfb47 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -153,7 +153,7 @@ function theme_test_system_info_alter(array &$info, Extension $file, $type) { if ($type == 'theme' && $file->getName() == 'test_theme' && \Drupal::state()->get('theme_test.modify_info_files')) { // Add a library to see if the system picks it up. $info += ['libraries' => []]; - $info['libraries'][] = 'core/backbone'; + $info['libraries'][] = 'core/once'; } } diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php index 64b9b87bde75..93242b6d8eba 100644 --- a/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php +++ b/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php @@ -101,7 +101,7 @@ public function testChanges() { $this->state->set('theme_test.modify_info_files', TRUE); $this->resetAll(); $active_theme = $this->themeManager->getActiveTheme(); - $this->assertEquals(['classy/base', 'classy/messages', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries()); + $this->assertEquals(['classy/base', 'classy/messages', 'core/normalize', 'test_theme/global-styling', 'core/once'], $active_theme->getLibraries()); } } diff --git a/core/modules/toolbar/toolbar.libraries.yml b/core/modules/toolbar/toolbar.libraries.yml index d8140142d704..eee3f4e2430c 100644 --- a/core/modules/toolbar/toolbar.libraries.yml +++ b/core/modules/toolbar/toolbar.libraries.yml @@ -24,7 +24,8 @@ toolbar: - core/drupalSettings - core/drupal.ajax - core/drupal.announce - - core/backbone + # @todo Remove this in https://www.drupal.org/project/drupal/issues/3204015 + - core/internal.backbone - core/once - core/drupal.displace - toolbar/toolbar.menu diff --git a/core/modules/tour/tour.libraries.yml b/core/modules/tour/tour.libraries.yml index f8f717b019f3..224370522c61 100644 --- a/core/modules/tour/tour.libraries.yml +++ b/core/modules/tour/tour.libraries.yml @@ -6,7 +6,8 @@ tour: - core/jquery - core/once - core/drupal - - core/backbone + # @todo Remove this in https://www.drupal.org/project/drupal/issues/3204011 + - core/internal.backbone - core/shepherd - tour/tour-styling diff --git a/core/scripts/js/vendor-update.js b/core/scripts/js/vendor-update.js index ef2b2c83463f..b7f2a210680c 100644 --- a/core/scripts/js/vendor-update.js +++ b/core/scripts/js/vendor-update.js @@ -55,7 +55,7 @@ const assetsFolder = `${coreFolder}/assets/vendor`; * is not defined the value of `pack` is used. * @prop {string} [library] * The key under which the library is declared in core.libraries.yml. - * @prop {Array} files + * @prop {Array} [files] * An array of files to be copied over. * - A string if the file has the same name and is at the same level in * the source and target folder. @@ -76,8 +76,13 @@ const assetsFolder = `${coreFolder}/assets/vendor`; const ASSET_LIST = [ { pack: 'backbone', + library: 'internal.backbone', files: ['backbone.js', 'backbone-min.js', 'backbone-min.map'], }, + // Only used to update the version number of the deprecated library. + { + pack: 'backbone', + }, { pack: 'css.escape', folder: 'css-escape', diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index a65139585e1c..d9dbdbdd2a7c 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -283,14 +283,14 @@ public function testBrowserConditionalComments() { * Tests JavaScript versioning. */ public function testVersionQueryString() { - $build['#attached']['library'][] = 'core/backbone'; + $build['#attached']['library'][] = 'core/once'; $assets = AttachedAssets::createFromRenderArray($build); $js = $this->assetResolver->getJsAssets($assets, FALSE)[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); $rendered_js = $this->renderer->renderPlain($js_render_array); - $this->assertStringContainsString('core/assets/vendor/backbone/backbone-min.js?v=1.4.0', $rendered_js, 'JavaScript version identifiers correctly appended to URLs'); + $this->assertStringContainsString('core/assets/vendor/once/once.min.js?v=1.0.1', $rendered_js, 'JavaScript version identifiers correctly appended to URLs'); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Asset/DeprecatedBackboneTest.php b/core/tests/Drupal/KernelTests/Core/Asset/DeprecatedBackboneTest.php new file mode 100644 index 000000000000..1cf562fb5ed9 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Asset/DeprecatedBackboneTest.php @@ -0,0 +1,38 @@ +<?php + +namespace Drupal\KernelTests\Core\Asset; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Checks the deprecation status of Backbone. + * + * @group Asset + * @group legacy + */ +class DeprecatedBackboneTest extends KernelTestBase { + + /** + * The library discovery service. + * + * @var \Drupal\Core\Asset\LibraryDiscoveryInterface + */ + protected $libraryDiscovery; + + /** + * {@inheritdoc} + */ + protected function setUp():void { + parent::setUp(); + $this->libraryDiscovery = $this->container->get('library.discovery'); + } + + /** + * Tests that the Backbone library is deprecated. + */ + public function testBackboneDeprecation() { + $this->libraryDiscovery->getLibraryByName('core', 'backbone'); + $this->expectDeprecation("The core/backbone asset library is deprecated in Drupal 9.4.0 and will be removed in Drupal 10.0.0."); + } + +} -- GitLab