The following functions have been refactored into methods on the NestedArray class, all calls should be replaced with direct calls to the methods the wrappers are calling:

drupal_merge_js_settings($settings_items) becomes \Drupal\Component\Utility\NestedArray::mergeDeepArray($settings_items, TRUE) (note the extra parameter)
drupal_merge_attached() becomes \Drupal\Component\Utility\NestedArray::mergeDeep()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ianthomas_uk’s picture

Issue summary: View changes
ianthomas_uk’s picture

Status: Active » Postponed

This will be a small patch and will conflict with #2221755: Remove uses of deprecated Element functions, so let's do that one first.

ianthomas_uk’s picture

Status: Postponed » Active

That patch is in.

These are new functions in 8.x, so don't need their own change record, but I have updated https://drupal.org/node/1911578 to refer to the NestedArray instead of drupal_merge_js_settings.

visabhishek’s picture

Status: Active » Needs review
FileSize
10.21 KB

i am uploading the initial patch, Please review...

Status: Needs review » Needs work
vastav’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
ianthomas_uk’s picture

  1. +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
    @@ -152,7 +152,7 @@ protected function ajaxRender(Request $request) {
    +      $settings = \Drupal\Component\Utility\NestedArray::mergeDeepArray($scripts['settings']['data'], TRUE);
    

    We should rely on 'use' statements, rather than having the fully qualified class name everywhere.

  2. +++ b/core/modules/system/lib/Drupal/system/Tests/Common/MergeAttachmentsTest.php
    @@ -221,10 +221,10 @@ function testJsSettingMerging() {
    +    // retained, it's up to the rest of the system (\Drupal\Component\Utility\NestedArray::mergeDeepArray())
    

    Comments should wrap at 80 characters

I've not looked into what is causing the failure, but the failing test is very relevant to the code we're changing so it does look like a problem with the patch rather than the testbot (there may have been a different failure before the retest though).

sriharsha.uppuluri’s picture

Status: Needs work » Needs review
FileSize
10.98 KB
2.72 KB

Updated the patch based on #8

Status: Needs review » Needs work
visabhishek’s picture

updated patch

Status: Needs review » Needs work
vastav’s picture

Status: Needs work » Needs review
ParisLiakos’s picture

Status: Needs review » Needs work

after applying the patch, i still find calls to drupal_merge_attached in drupal_pre_render_links, _drupal_render_process_post_render_cache and drupal_render_collect_attached

visabhishek’s picture

patch updated as per #14 and drupal_merge_attached () is also removed from common.inc

ParisLiakos’s picture

thanks!
i dont think we should remove drupal_merge_attached() itself in this issue though

visabhishek’s picture

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

thank you!

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
@@ -152,7 +153,7 @@ protected function ajaxRender(Request $request) {
-      $settings = drupal_merge_js_settings($scripts['settings']['data']);
+      $settings = NestedArray::mergeDeepArray($scripts['settings']['data'], TRUE);

+++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php
@@ -68,7 +69,7 @@ public function render(array $js_assets) {
-          $element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";
+          $element['#value'] = 'var drupalSettings = ' . Json::encode(NestedArray::mergeDeepArray($js_asset['data'], TRUE)) . ";";

+++ b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php
@@ -76,7 +76,7 @@ public function upload(Request $request) {
-    $settings = drupal_merge_js_settings($js['settings']['data']);
+    $settings = NestedArray::mergeDeepArray($js['settings']['data'], TRUE);

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -1770,7 +1770,7 @@ protected function drupalProcessAjaxResponse($content, array $ajax_response, arr
-          $drupal_settings = drupal_merge_js_settings(array($drupal_settings, $command['settings']));
+          $drupal_settings = NestedArray::mergeDeepArray(array($drupal_settings, $command['settings']), TRUE);

@Wim Leers was very adament about adding this as a separate function, so this should be left alone. At some point we should replace it with a non-procedural alternative, but that's for a separate issue.

ianthomas_uk’s picture

Status: Needs work » Closed (won't fix)

Thanks @tstockler. Actually he was adamant about having both functions as usability wrappers, see #2113015: Add drupal_merge_attached() function, to merge #attached assets, therefore this is a won't fix. Moving the wrappers into a class would be a separate issue.

I've changed the CR back to refer to the wrapper function.