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:

#555762: Changes to batch API

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.

Comments

gdd’s picture

Title: hook_block_alter() is undocumented » hook_batch_alter() is undocumented

oops

gdd’s picture

StatusFileSize
new908 bytes

There 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.

aspilicious’s picture

Status: Needs work » Needs review

Of course this needs review

jhodgdon’s picture

Status: Needs review » Needs work

Actually, no, heyrocker left it as "needs work" because there is no function body (read original posting).

aspilicious’s picture

Ok i'm srry

jhodgdon’s picture

No problem. Want to take a stab at writing the function body? :)

aspilicious’s picture

Nop I just ordered drupal pro development 3 in pre release. Maybe when I finished the book ;)

trevjs’s picture

jhodgdon’s picture

Good find! Yes indeed. :)

trevjs’s picture

This 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.

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB

OK, here's a patch with a function body, taken from overlay.module() as suggested above.

gdd’s picture

StatusFileSize
new1.21 KB

With 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.

Status: Needs review » Needs work

The last submitted patch, 717602.patch, failed testing.

jhodgdon’s picture

It 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?

gdd’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB

You caught me, I thought that worked! Anyways here is a new patch.

trevjs’s picture

Going 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:

 @param $batch
 *   An array defining the batch. The following keys can be used -- only
 *   'operations' is required, and batch_init() provides default values for
 *   the messages.
 *  - 'operations': Array of function calls to be performed.
 *     Example:
 *     @code
 *     array(
 *       array('my_function_1', array($arg1)),
 *       array('my_function_2', array($arg2_1, $arg2_2)),
 *     )
 *     @endcode
 *   - 'title': Title for the progress page. Only safe strings should be passed.
 *     Defaults to t('Processing').
 *   - 'init_message': Message displayed while the processing is initialized.
 *     Defaults to t('Initializing.').
 *   - 'progress_message': Message displayed while processing the batch.
 *     Available placeholders are @current, @remaining, @total, @percentage,
 *     @estimate and @elapsed. Defaults to t('Completed @current of @total.').
 *   - 'error_message': Message displayed if an error occurred while processing
 *     the batch. Defaults to t('An error has occurred.').
 *   - 'finished': Name of a function to be executed after the batch has
 *     completed. This should be used to perform any result massaging that
 *     may be needed, and possibly save data in $_SESSION for display after
 *     final page redirection.
 *   - 'file': Path to the file containing the definitions of the
 *     'operations' and 'finished' functions, for instance if they don't
 *     reside in the main .module file. The path should be relative to
 *     base_path(), and thus should be built using drupal_get_path().
 *   - 'css': Array of paths to CSS files to be used on the progress page.
 *   - 'url_options': options passed to url() when constructing redirect
 *     URLs for the batch.

One thing to note, the function actually calls the argument batch_definition, but then the docs use $batch.

jhodgdon’s picture

A 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.

gdd’s picture

There 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.

jhodgdon’s picture

I 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

+ *   The associative array of batch information. See batch_set() for details on what this could contain.

(with proper 80-character line wrapping).

Or something like that... maybe "contains" instead of "could contain"?

robeano’s picture

Assigned: Unassigned » robeano

jhodgdon forced me to take this one.

robeano’s picture

StatusFileSize
new1.32 KB

Added sentence jhodgdon recommended. Ready for review.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD! Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.