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.
These need documenting now we have a standard for documenting callbacks: http://drupal.org/node/1354#callback-def
Comment | File | Size | Author |
---|---|---|---|
#14 | 1948566.14.drupal.batch-api-callbacks-docs.patch | 8.16 KB | joachim |
#12 | 1948566.12.drupal.batch-api-callbacks-docs.patch | 4.75 KB | joachim |
#5 | 1948566.drupal.batch-api-callbacks-docs.patch | 4.73 KB | joachim |
Comments
Comment #1
jhodgdonWhat this issue is about: we now have standards (see link above) for documenting callback function signatures.
So what we need to do is look at the Batch API functions in Drupal 8 and 7, and see if they require the caller to pass in functions with a particular signature; if so, define them as callback_batch_foo() in system.api.php and then amend the batch function documentation to refer to them (see standards link above).
Might be a good novice project?
Comment #2
joachim CreditAttribution: joachim commentedGiven batch_set() lives in form.inc, this should logically go in the form.api.php file that is about to be created by the issue on documenting formAPI callbacks.
Here's a fun problem: callback_batch_process() has a variable number of params, but the variability is at the *start*: no matter what params are defined, &$context is always the *last* param.
How should that be represented in the @param items?
Comment #3
jhodgdonYou can do something like:
Comment #4
joachim CreditAttribution: joachim commentedOk, will do. I'll work on a patch for this once #2094145: document Form API #process callback in form.api.php is in and the form.api.php file exists.
Comment #5
joachim CreditAttribution: joachim commentedThe patch for form #process callbacks is just taking forever, so here's a patch which clashes with it :p
I can reroll the patch at #2094145: document Form API #process callback in form.api.php when this gets in.
I'm also not going to go round updating all the instances of this callback. My experience at #2094145: document Form API #process callback in form.api.php shows that this is much better left for a follow-up.
Comment #7
joachim CreditAttribution: joachim commentedSetting back to needs review -- api.php files shouldn't be getting parsed!
Comment #8
jhodgdonUm, yes. They need to have valid PHP in them, or the API module will not be able to parse them.
Comment #9
joachim CreditAttribution: joachim commentedAh. I didn't realise the grammar parser parsed it by interpreting the PHP.
In which case, this line is a problem:
How should this be handled?
Comment #10
jhodgdonHow about something like this:
Comment #11
jhodgdonComment #12
joachim CreditAttribution: joachim commentedFinally got round to this.
I've called it $MULTIPLE_PARAMS in capitals to make it dead clear that it's not just a normal parameter called $params!
Comment #13
jhodgdonI think that is a reasonable way to document this function.
So... This is nearly ready to go. A few things I noticed:
a) Our callback standards:
https://drupal.org/node/1354#callback-def
say we're supposed to have a line like
in the callback function docs. This is missing from both of the callbacks.
b)
"finished callback"... Should that be callback_batch_finished()? or at least be in quotes or something?
c)
before "however" it should be ; not ,
d)
Um... Something got left out here? And that 2nd to last line is too long. Actually, the whole sandbox section doesn't make much sense to me.
e) callback_batch_finished() has no @param or @return docs. It may not need @return, but does have several parameters.
f) Doesn't the batch_set() documentation need to reference these new callback definitions?
Comment #14
joachim CreditAttribution: joachim commentedI think this fixes everything.
> Actually, the whole sandbox section doesn't make much sense to me.
I've added a bit more about it. Hope that helps.
Comment #15
jhodgdonMuch better! I like all of the documentation, and I think the examples are very clear. The only thing that I wondered about was in the operations example, whether it would be clear that $option1 and $option2 local variables were supposed to be part of the parameters? Maybe a code comment at the top explaining this would be helpful?
Anyway, I guess we could commit this as it is... the only other thing that might be helpful though would be to update documentation for actual operations/finished callbacks in Core to reference this documentation. Which you can find by looking at api.drupal.org for who calls batch_set(). I wouldn't document the ones used it tests (kind of pointless) but maybe the others? Or we can just leave that out. Thoughts?
Comment #16
joachim CreditAttribution: joachim commented> update documentation for actual operations/finished callbacks in Core to reference this documentation. Which you can find by looking at api.drupal.org for who calls batch_set()
That's definitely something that needs doing, but I would really like to leave that as a follow-up. Doing it all in one go on the form #process callback patch has really burnt me out :(
Comment #17
jhodgdonFair enough. Let's just get this in then.
Comment #18
jhodgdonThere's an "avoid commit conflicts" issue touching form.inc
#1996238: Replace hook_library_info() by *.libraries.yml file
so I'm going to be extra-cautious and wait to commit this until that's resolved, even though I am pretty sure there isn't a direct conflict with this patch.
Comment #19
jhodgdonI got leave from the other issue person to commit this, so it's committed to 8.x. The patch also worked OK for 7.x, so I committed it there too. Thanks again!
Comment #20
joachim CreditAttribution: joachim commentedBrilliant, thanks!
I've filed the promised follow-up: #2195183: document Batch API callbacks as callback implementations.
(And of course now that I see the actual text on api.d.o I can see ways to improve it, but that can wait... :)