From a2c58dda71d6076f8bd792be609935ec583f258b Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 30 Dec 2021 21:05:26 +0000 Subject: [PATCH] Issue #3197553 by beatrizrodrigues, longwave, daffie: Deprecate drupal_js_defaults() --- core/includes/common.inc | 6 +++++- core/lib/Drupal/Core/Asset/AssetResolverInterface.php | 3 +-- core/lib/Drupal/Core/Render/theme.api.php | 1 - .../KernelTests/Core/Asset/AttachedAssetsTest.php | 10 ++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index f6a42a17109a..374a5f6b7d39 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -201,9 +201,13 @@ function base_path() { * @param $data * (optional) The default data parameter for the JavaScript asset array. * - * @see hook_js_alter() + * @deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3197679 */ function drupal_js_defaults($data = NULL) { + @trigger_error('drupal_js_defaults() is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. No direct replacement is provided. See https://www.drupal.org/node/3197679', E_USER_DEPRECATED); return [ 'type' => 'file', 'group' => JS_DEFAULT, diff --git a/core/lib/Drupal/Core/Asset/AssetResolverInterface.php b/core/lib/Drupal/Core/Asset/AssetResolverInterface.php index 5bde3b45f1b1..66f6ec095ab7 100644 --- a/core/lib/Drupal/Core/Asset/AssetResolverInterface.php +++ b/core/lib/Drupal/Core/Asset/AssetResolverInterface.php @@ -60,8 +60,7 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize); * Note that hook_js_alter(&$javascript) is called during this function call * to allow alterations of the JavaScript during its presentation. The correct * way to add JavaScript during hook_js_alter() is to add another element to - * the $javascript array, deriving from drupal_js_defaults(). See - * locale_js_alter() for an example of this. + * the $javascript array. See locale_js_alter() for an example of this. * * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets * The assets attached to the current response. diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index 584ab733278b..fcf80e2923b7 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -853,7 +853,6 @@ function hook_element_plugin_alter(array &$definitions) { * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets * The assets attached to the current response. * - * @see drupal_js_defaults() * @see \Drupal\Core\Asset\AssetResolver */ function hook_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets) { diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index 54700f93f05e..1687bd2a97bc 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -487,4 +487,14 @@ public function testAddJsFileWithQueryString() { $this->assertStringContainsString('<script src="' . str_replace('&', '&', $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2')) . '&' . $query_string . '"></script>', $rendered_js, 'JavaScript file with query string gets version query string correctly appended.'); } + /** + * Tests deprecated drupal_js_defaults() function. + * + * @group legacy + */ + public function testDeprecatedDrupalJsDefaults() { + $this->expectDeprecation('drupal_js_defaults() is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. No direct replacement is provided. See https://www.drupal.org/node/3197679'); + $this->assertIsArray(drupal_js_defaults()); + } + } -- GitLab