ajax_render behaves differently in regards to changing settings from hook_js_alter(). It throws away the altered copy and uses an unaltered copy.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, ajax_render_alter_settings.patch, failed testing.

ygerasimov’s picture

Status: Needs work » Needs review

Bug confirmed. Patch solves the issue. Thank you.

kenianbei’s picture

Same here, patch fixes issue for me as well.

kenianbei’s picture

ajax_render_alter_settings.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, ajax_render_alter_settings.patch, failed testing.

balsama’s picture

Status: Needs work » Needs review
FileSize
1.27 KB

Re-roll attached.

balazswmann’s picture

I have attached the Drupal 7 version of the last submitted patch.

czigor’s picture

A reroll of #7.

mgifford’s picture

Shouldn't this be Needs Work rather than Needs Review?

Status: Needs review » Needs work

The last submitted patch, 6: ajax_render_alter_settings-1448796-6.patch, failed testing.

balsama’s picture

@mgifford Well, now it does. It passed tests 15 months ago, but obviously needs a re-roll again now. Unfortunately, there's not much motivation to re-roll it again if it's just going to languish for another 15 months :)

mgifford’s picture

Issue tags: +Needs reroll

Some issues get forgotten in the issue queues. Often it just takes a small community of folks to keep nudging it to the top.

mgifford’s picture

Issue tags: -Needs reroll

Well it seems that the function ajax_render() no longer exists. Closest I could find was:

core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php:
$this->moduleHandler->alter('ajax_render', $commands);

or maybe:

core/lib/Drupal/Core/Form/form.api.php:
function hook_ajax_render_alter(array &$data) {

So should we mark this issue as closed?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update, +Needs steps to reproduce, +Bug Smash Initiative

@balsama @czigor any chance you could test if this still impacts Drupal 9?

This needs steps to reproduce and and issue summary update

balsama’s picture

Sorry, but I'm not sure I knew how to reproduce when I originally interacted with this issue - much less now. I can't imagine why I was involved and I don't understand the IS now. :p

mdupont’s picture

AFAICS, Drupal 9 is not impacted. AjaxResponseAttachmentsProcessor::buildAttachmentsCommands(), which invokes hook_ajax_render_alter(), correctly handles alterations made to DrupalSettings through hook_js_alter() / hook_js_settings_alter().

See also AssetResolver::getJsAssets(), which is called from the function above and handles the Settings alteration.

larowlan’s picture

So does that mean this should be moved to D7?

mdupont’s picture

Version: 8.9.x-dev » 7.x-dev

Let's move it to D7 indeed.

mdupont’s picture

Cannot reproduce it on the latest Drupal 7.x. Here is what I've done:

  1. Installed latest Drupal 7 from git, standard profile
  2. Installed Examples module
  3. Enabled Ajax Example module
  4. Wrote a small custom module which implements hook_js_alter() with the following code :
    function custom_module_js_alter(&$javascript) {
      $javascript['settings']['data'][] = ['test' => 1];
    }
    
  5. Enabled the custom module
  6. Logged into Drupal 7 as admin, went to create a new Basic page
  7. Clicked on the "Ajax example 1" checkbox on the node creation form, which triggers an Ajax call which makes use of ajax_render()

Result: I can correctly see my "test: 1" setting both in the Ajax HTTP response and in the page when calling console.log(Drupal.settings); from the javascript console.

I guess we can close this issue as CNR.

larowlan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Thanks @mdupont