Steps to repeat
View API page: https://api.drupal.org/api/drupal/core%21includes%21ajax.inc/group/ajax/8
Problem / Motivation
The documentation in the ajax @defgroup in ajax.inc has at least a few things that need updating. The example code for building a form is incorrect, as well as the usage of \Drupal::formBuilder()->getForm('ajax_example_simplest'); The form should really be defined as an implementation of FormBuilderInterface and the class name passed to getForm().
There are also references to functions like ajax_command_replace() and ajax_command_changed() that don't even exist in D8 so we should probably fix those examples as well.
Overall, I think this page could do with a complete review to for accuracy and to get updated examples that are of a high enough quality that we would be okay with people copy/pasting them into their own code.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2256593-ajax-docs-10.patch | 30.41 KB | jhodgdon |
| #10 | 2256593-ajax-docs-9.patch | 30.41 KB | jhodgdon |
| #8 | interdiff.txt | 1.1 KB | jhodgdon |
| #8 | 2256593-ajax-docs-8.patch | 30.33 KB | jhodgdon |
Comments
Comment #1
eojthebraveComment #2
jhodgdonThanks! This definitely needs to be done. Adding to the "api landing page" meta, since this is one of the landing topics.
Comment #3
jhodgdonI think I can take this one on. It's been partially updated for D8, but things have changed since it was first done so it needs more updates.
Comment #4
jhodgdonHere's a first pass at a patch.
As a note, in D7 there was a separate topic that listed the available Ajax commands. I figured we didn't really need 2 topics, so I added all the available command classes with @ingroup to this topic.
The text has (obviously) also been completely rewritten. I believe it to be accurate, and took examples from actual, presumably working code. Obviously needs a review; it should hopefully, at a minimum, be a lot better than the mostly D7 disorganized mess that was there!
Comment #5
dawehnerIn the previous bit you changed it from using framework to API which is an improvement TBH. Should we also mention the other way: define route which returns an Ajax Response object? I see it is written below, not sure how it will be displayed at the end of the day.
Do we support routes + route parameters here already? Just curios
OT: Did we considered to not use ajax IDs but classes/data attributes?
I am not sure whether it really makes sense to mention this here. The autocompletion framework is orthogonal to the ajax one.
Comment #6
jhodgdonThanks for the review! I think I've addressed #1... a few notes on the other comments:
#2 - I do not see anything in core using routes instead of paths in #ajax, but I didn't look at everything. No idea really.
#3 - I also have no idea on that. I just wrote up what I saw being used, and/or borrowed documentation from other sources.
#4 - As far as I know, the only other place we document autocomplete is in the form API reference, which is outdated especially for Drupal 8, not to mention nearly impossible to patch. Autocompletes are Ajax, although I agree the framework for handling autocompletes in Drupal is not the same at all as the other Ajax stuff.... I'd prefer to keep it in the patch though, since it's pretty simple and it doesn't really need its own topic, I think?
New patch...
Comment #7
jhodgdonThis needs more proofreading. Let me take another look at it...
Comment #8
jhodgdonOK, not much! But I noticed two typos while working on something else and referring to this patch.
Comment #9
webchickShoot. No longer applies.
Comment #10
jhodgdonSomething in there changed, needed a reroll.
Comment #11
jhodgdonMissed one thing in the reroll
Comment #12
webchickOk cool, this sat here for a month without any issues so I'm going to go ahead and get this in.
Committed and pushed to 8.x. Thanks!