Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
#1812866: Rebuild the server side AJAX API refactors the AJAX API to classes, however it doesn't touch any of the actual commands.
A lot of these could be decouple from jQuery, and some like restripe could simply be removed now that we don't support browsers that need it in the first place (yay!).
Comments
Comment #1
effulgentsia CreditAttribution: effulgentsia commented#1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors removes it, but that patch hasn't landed yet.
Comment #2
effulgentsia CreditAttribution: effulgentsia commentedFrom #1533366-49: Simplify and optimize Drupal.ajax() instantiation and implementation:
Half of our server-side commands reduce to an 'insert', and I'd be in favor of removing them, and making PHP code just use the Insert command and pass the desired 'method'. Then again, now that we have these commands as Drupal\Core\Ajax\* classes, if we want to leave the specific InsertCommand subclasses around, but maybe change their render() implementation to call parent::render(), or remove the render() override and instead give them a constructor that sets $this->method, we could do that too.
We also have the 'invoke' command for simple 1-line jQuery method invocations, and if we're willing to keep it, then we can drop the 'css' and 'data' commands, unless we decide that we want those commands to be available without jQuery.
What we then have left is a pretty small set of commands: insert, remove, changed, invoke, add_css, settings, restripe, and alert. We can remove 'restripe' if we get #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors in. I think we might want to replace 'alert' with some more generic way of dealing with errors, warnings, and notices. The remaining commands, though, seem like the right "API" for server-side code to communicate to the client, and I don't think it makes sense to reduce it further. However, we may want to look at other AJAXy frameworks like Backbone to see if they've come up with better or more standard APIs we'd rather model.
Comment #3
Crell CreditAttribution: Crell commentedNote that Views has a number of commands of its own that may or may not make sense to genericize: #1843224: Convert Views Ajax commands to new Ajax API
Comment #16
catchDuplicate of #3189416: Remove jQuery Form dependency from misc/ajax.js now.