Problem/Motivation
We want to merge an AjaxResponse with another AjaxResponse and this currently not possible.
Inside of MediaLibraryWidget the code is returning an AjaxResponse.
Our code is also returning AjaxReponse and we wanted to merge them.
Merge request is provided.
If there is a better option please let me know.
Steps to reproduce
NA
Proposed resolution
Review merge request.
Added a setCommands function:
public function setCommands($commands) {
$this->commands = array_merge($this->commands, $commands);
}
Remaining tasks
Review
Release notes snippet
Added setCommands function to AjaxResponse class to allow merging of AjaxResponses.
Comment | File | Size | Author |
---|---|---|---|
#3 | 3343670-nr-bot.txt | 1.28 KB | needs-review-queue-bot |
Issue fork drupal-3343670
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #5
enaznin CreditAttribution: enaznin at Axelerant for Drupal India Association commentedComment #6
nod_There is an
addCommand
method that does much more than a simple array_merge so there is bound to be issues doing it this way.MR should be against 10.1.x since that is the current dev version
Naming of the new function is not ideal. It's not about setting commands, I'd be more of a
mergeCommands
methodAt the moment commands can be added the addCommand method, so what the issue raised could be worked around @Mschudders would that be enough?
Comment #7
Mschudders CreditAttribution: Mschudders at Calibrate commented@nod thanks for the information.
Indeed the naming was crappy.
Created a new branch against 10.1.x with the bot fixes + naming changes to the function.
Let me elaborate why this is usefull:
I have overridden
MediaLibraryWidget
so that I can attach an extra Ajax command to the callback of updateWidget:Since
updateWidget
returns an AjaxReponse already it isn't easy to add an additional command to it.If you retrieve the commands from AjaxReponse it's already an rendered array and you cannot set them again. That's why I have added a mergeCommands function so that you can merge the commands.
I hope this clarifies things.
Comment #11
tim-dielsRebased to be up-to-date.
Comment #12
smustgrave CreditAttribution: smustgrave at Mobomo commentedCan the MR be updated for 11.x as that's the current development branch.
Also could use a simple test assertion to show it's working.
Comment #14
tim-dielsStill needs test.
Comment #15
tim-dielsThe module Layout Builder Extras - live update requires this patch.