My first issue filed against Views VDC! :-)
#1812866: Rebuild the server side AJAX API introduced a new server-side API for Ajax commands that plays nicer with the new Kernel/Request/Response pipeline. The change notice is at http://drupal.org/node/1843212
The Views commands in views/includes/ajax.inc need to be updated for the new API, and possibly refactored in the process. (I defer to the Views team on that front.)
I didn't see an existing issue where this would be relevant, but if I missed one feel free to consolidate.
Comment | File | Size | Author |
---|---|---|---|
#30 | drupal-1843224-30.patch | 23.39 KB | dawehner |
#28 | drupal-1843224-28.patch | 23.25 KB | dawehner |
#24 | drupal-1843224-24.patch | 23.22 KB | dawehner |
#20 | drupal-1843224-20.patch | 23.78 KB | dawehner |
#20 | interdiff.txt | 5.52 KB | dawehner |
Comments
Comment #1
tim.plunkettI've converted one command, and replaced a couple usages. The rest should follow suit.
Comment #2
dawehnerWe should reconsider the removing as it is pretty helpful: If you just use the generic alter hook (hook_ajax_render_alter) you simple have not the context of the view. There are several contrib modules which uses that hook to inject behavior.
Working on converting the other methods.
Comment #3
dawehnerWe should reconsider the removing as it is pretty helpful: If you just use the generic alter hook (hook_ajax_render_alter) you simple have not the context of the view. There are several contrib modules which uses that hook to inject behavior.
Working on converting the other methods.
Comment #4
dawehnerIt seems to be that my actual response got nucked and replaced by the previous one
Here are some points which describes the changes of the patch
all commands. You could also use the $response object though then we would need a lot of custom setters/getters.
Comment #5
tim.plunkettThis should be
(optional) The URL of the form, defaults to NULL.
That looks a bit odd.
I agree about the alter, subclassing the response for that case sounds viable.
Comment #6
dawehnerJust a bit?
Comment #7
miro_dietikerChecked for consistency, seems fine. Covers all occurrences of commands. Fully documented.
It's the rendered "commands" from the AjaxResponse - the argument received is even $commands. Dunno what naming is better. Possibly even "Alter the response commands"? ;-)
Comment #8
Crell CreditAttribution: Crell commentedWhy do we need an alter here? There's already kernel.response which happens pre-prepare(), if someone really wants to muck with the response object. That's what that event is for. I'm really trying hard to keep alter calls out of the new pieces of the system, as that's where a lot of our non-deterministic spaghetti comes from.
Comment #9
dawehnerUps, right i started with converting the documentation when i realized that it's not really useful to alter $response as you don't have access to the commands.
Is there some documentation already to at least understand the big picture here?
Okay, so let's assume someone wants to do two things:
What would they do? As written before, there is currently no way from outside a response object to change the values.
Comment #10
Crell CreditAttribution: Crell commentedIf it's really a necessary feature, then we would likely be better off adding a getCommands() method to the AjaxResponse class that simply returns the array of commands by reference. Then code that needs to muck with it can implement the kernel.response listener, check that it's an AjaxResponse, call getCommands(), and molest it as appropriate. That's similar to what the select query builder offers in terms of getters-for-mucking.
Comment #11
dawehnerThanks for the idea.
Do we already have an documentation standard how to document available listeners or an example how to use it?
Comment #12
Crell CreditAttribution: Crell commentedFor Drupal-defined ones: #1751116: [policy, then patch] Determine standard for documenting Events and Subscribers/Listeners
For Symfony defined ones: http://symfony.com/doc/current/index.html
Comment #13
dawehnerViewAjaxResponse or ViewAwareAjaxResponse? Every class using "aware" seems to be connected with the container, but you should know that better :)
Removed the alter hook, added the method and added a todo in the views.api.php file.
Comment #14
Crell CreditAttribution: Crell commented"Aware" seems more appropriate in cases where the object is leveraging another object, not when it's just an enhanced data collector. So ViewsAjaxResponse.
That's looking much better there. Not setting RTBC because I've not looked at the Views-specific bits at all. :-) I'll let someone who knows Views properly handle that.
Comment #15
dawehnerIt's now ViewAjaxResponse as it's not about Views but about a view.
Rerolled against HEAD.
Comment #17
dawehner#15: drupal-1843224-15.patch queued for re-testing.
Comment #18
damiankloip CreditAttribution: damiankloip commentedShould we doc here that it is returned by reference? And should it be something like 'Returns all stored commands' or 'Returns an array of all commands' instead?
Should we use HighlightCommand instead and be proper? or we 'HiLite' things in JS, I'm not sure :)
buttonS ?
So much tidier!
So I guess we need to add in stuff about altering the response? Then I think this is looking pretty ready.
Comment #19
dawehnerWhen i asked in IRC it wasn't clear how to document that something is returned by reference.
You simply can't argue against a native speaker :)
I guess the way to do it, is to register your event subscriber in the container and then listen to some kind of event.
Comment #20
dawehnerI think we simply don't have a clue how to document that properly at the moment and it would be somehow the generic way to alter the response.
What about the following?
Comment #21
damiankloip CreditAttribution: damiankloip commentedI think this looks good, we should probably get a review from an 'Ajax guy' though :)
Comment #22
tim.plunkettCrell was happy with it from the Ajax side, and it looks good from the Views side.
Comment #23
sunHm.
I tried to understand the comments #9 and #10... but I'm not sure whether this makes sense?
1) @Crell basically wants each and every custom thing to implement an own command, instead of allowing to alter settings. (He calls it "spaghetti", others would call it "real world needs and use-cases".)
2) The actual, implemented stop-gap workaround allows for much more than what is actually asked for; it allows to retrieve + alter all commands of the response — which essentially equals
hook_page_alter()
. That's OK-ish (though perhaps also not) for the use-case of a module that wants to alter entire Ajax responses based on various conditions, but that's a completely different thing than the case of 1) creating a command and 2) altering its settings before 3) adding it to the response, no?3) To achieve that, I'd think that a &getSettings() method on the Ajax command base class would be more appropriate; e.g., like this:
4) In any case, this method is not used anywhere in this patch, and I think the phpDoc of the method should clarify why this method allows to assign and alter Ajax commands by reference.
If you agree but disagree with hashing out this detail in this issue, then let's remove that getCommands() method from this patch and let's create a follow-up issue to discuss it separately. :)
Comment #24
dawehnerSo one use-case is to remove the scroll-to-top functionality, so it's not about just altering single ones, but removing them.
Let's remove this command from that patch and discuss that in a follow up.
Comment #26
dawehner#24: drupal-1843224-24.patch queued for re-testing.
Comment #28
dawehnerRerolled.
Comment #29
dawehnerLet's wait for #1870764: Add an ajax command which makes it easy to use the dialog API in complex cases
Comment #30
dawehnerLet's get that better in now and rework later.
Comment #31
Crell CreditAttribution: Crell commentedI don't really see how the ViewsAjaxResponse is being used here. There's one use of it in the patch, and the code in question doesn't seem to benefit from it.
Otherwise this looks OK to me, but I am not RTBCing because I don't know Views well enough for RTBC-levels of confidence.
Comment #32
dawehnerPeople alter the commands of views (there are many contrib modules doing that) so we need some kind of way to let the distinct easily and get the view object as well.
Comment #33
Crell CreditAttribution: Crell commentedAh, OK. And it's even documented to that effect. :-) I don't see the alter call though. Is that just outside of the patch's code scope, or am I blind?
Comment #34
dawehnerSee here :)
Comment #35
Crell CreditAttribution: Crell commentedLOL. OK, I'll stop now. Still not RTBCing because that should be left to someone more familiar with Views.
Comment #36
tim.plunkettI think that @todo is covered by #1751116: [policy, then patch] Determine standard for documenting Events and Subscribers/Listeners, we're done here!
Amazing work @dawehner.
Comment #37
catchLooks good to me, I think that follow-up is OK as it is. Committed/pushed to 8.x.