An item from the undocumented hooks meta-issue
#675046: Make sure all hooks in D7 have documentation
So I have written the documentation for this patch as attached, but I don't really have a good understanding of the use case to be confident in it, or to add any sample code. To the best of my knowledge this is not actually implemented anywhere in core, it is only for contrib's use. The original issue:
While this talks about needing an alter hook for other environments (specifically command line), it doesn't say why this is needed or what you need to do to make such things happen. Also, the fact that you will have to add in your own data in order to be able to identify a specific batch makes the sample code problematic. So I've gone as far as I feel like I can with this and hopefully someone more knowledgeable can chime in or land it.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 717602.patch | 1.32 KB | robeano |
| #15 | 717602.patch | 1.25 KB | gdd |
| #12 | 717602.patch | 1.21 KB | gdd |
| #11 | 717602_withbody.patch | 1.29 KB | jhodgdon |
| #2 | hook_batch_alter.patch | 908 bytes | gdd |
Comments
Comment #1
gddoops
Comment #2
gddThere was a small typo in the previous batch since the parameter in the code sample function definition was not indicated to be passed by reference.
Comment #3
aspilicious commentedOf course this needs review
Comment #4
jhodgdonActually, no, heyrocker left it as "needs work" because there is no function body (read original posting).
Comment #5
aspilicious commentedOk i'm srry
Comment #6
jhodgdonNo problem. Want to take a stab at writing the function body? :)
Comment #7
aspilicious commentedNop I just ordered drupal pro development 3 in pre release. Maybe when I finished the book ;)
Comment #8
trevjs commentedIs this a good example of its use?
http://api.drupal.org/api/function/overlay_batch_alter/7
Comment #9
jhodgdonGood find! Yes indeed. :)
Comment #10
trevjs commentedThis might help as well, it has a list of possible keys for $batch
batch_set: http://api.drupal.org/api/function/batch_set/7
I'm new here, so please correct me if I'm wrong about this, but I think we can use the same list of keys without any change in the wording.
Comment #11
jhodgdonOK, here's a patch with a function body, taken from overlay.module() as suggested above.
Comment #12
gddWith the new function body in place, I no longer think the comment about working from the command line is relevant, and in fact is kind of confusing, because it makes me think the sample code will be related. So here is a patch that removes that comment. Otherwise I think this is RTBC.
Comment #14
jhodgdonIt looks like maybe you just edited the patch instead of applying, editing, doing the diff again and the line numbers are confused, so the patch format is invalid?
Comment #15
gddYou caught me, I thought that worked! Anyways here is a new patch.
Comment #16
trevjs commentedGoing back to my comment in #10, do we need to work in this list of keys for $batch?
Here is what I found from batch set:
One thing to note, the function actually calls the argument batch_definition, but then the docs use $batch.
Comment #17
jhodgdonA good point about having more detail... but maybe instead of documenting it we could just say explicitly that the array being modified is the input to batch_set() or see batch_set() for a list of what the array might contain, or something like that?
Not sure about your last comment trevjs, though. It looks like the whole doc is consistently using $batch.
Comment #18
gddThere is a @see batch_set() in the comments already. I could go either way about specifying the whole array. We do do it in some other places in system.api.php so I don't really have a problem with it.
Comment #19
jhodgdonI don't think we need to list all the possibilities here, since this hook is just allowing modules to alter the batch information anyway....
How about just
(with proper 80-character line wrapping).
Or something like that... maybe "contains" instead of "could contain"?
Comment #20
robeano commentedjhodgdon forced me to take this one.
Comment #21
robeano commentedAdded sentence jhodgdon recommended. Ready for review.
Comment #22
jhodgdonLooks good to me.
Comment #23
webchickCommitted to HEAD! Thanks!