API page: http://api.drupal.org/api/drupal/includes%21form.inc/function/batch_set/7

Enter a descriptive title (above) relating to batch_set, then describe the problem you have found:

The function argument is $batch_definition, but the @param doc does not match this (it says $batch).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmarkel’s picture

Assigned: Unassigned » jmarkel
Status: Active » Needs review
FileSize
4.76 KB

Here's a patch

jhodgdon’s picture

Status: Needs review » Needs work

I don't think this chunk belongs in the patch:

--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -4370,7 +4370,7 @@ function element_validate_number($element, &$form_state) {
  *   'finished' => 'my_finished_callback',
  *   'file' => 'path_to_file_containing_myfunctions',
  * );
- * batch_set($batch);
+ * batch_set($batch_definition);

That is part of a code example, and the variable above there is definitely $batch, so that needs to stay as it was.

Regarding the other changes... If you want to bring the whole function up to coding standards (which is always nice!), you might also want to fix this bit:

 * @param $batch_definition
  *   An array defining the batch. The following keys can be used -- only
  *   'operations' is required, and batch_init() provides default values for
  *   the messages.

It should probably say something more like:

An associative array defining the batch, with the following elements (all optional except where noted):

And then the list below should use (required) on that one required element.

Also, the paragraph at the end... If it is part of the @param, then there should not be a blank line before it. If it is not part of the @param, then it should be moved up to before the @param section of the docs.

jmarkel’s picture

Status: Needs work » Needs review
FileSize
4.48 KB

First bit - yeah, a bit of overzealousness on my part.

The rest - okay, try this one, which is significantly different. Things have been moved around (as suggested) and reworded for, I hope, a little more clarity and simplicity.

Note that I changed "Opens a new batch" to "Adds a new batch." "Opens" suggests that this function initiates a batch that already exists. This function, though, creates ( i.e. "Adds,") a new batch.

jhodgdon’s picture

Status: Needs review » Needs work

Much better!

So... I know you didn't write these parts, but what do you think about the following ideas to further improve this documentation:

a) In the top paragraph, explaining about batches, it says:

Batch operations are added as new batch sets. Batch sets are used to provide clean code independence, ...

But really, I think the main reason we use batches is not to provide independence, but to process things that might take a while, right? That is not really explained anywhere, so it might be good to add something basic about the purpose of batches to that paragraph.

b) In the 'title' list item, it says: "Only safe strings should be passed." ... I always suggest this wording be changed whenever I see it in @param documentation. It should at least say "passed in", or better yet reword the whole list item to something like:

title: A safe, translated string to use as the title for the progress page. Defaults to t('Processing').

Other than those two suggestions, this looks good! Thanks!

jmarkel’s picture

Status: Needs work » Needs review
FileSize
4.87 KB

Consolidating your suggestions, jhodgdon.

I'm not completely confident of the new description, even if it is mostly cribbed from the 'Batch operations' documentation. I'm needing fresh eyes...

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I think this looks great, thanks! I'll get it committed when I get back to my main computer (probably tomorrow),.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I committed this to 8.x. Needs port to 7.x.

jmarkel’s picture

Assigned: jmarkel » Unassigned
Status: Patch (to be ported) » Needs review
FileSize
4.85 KB

Re-rolled for 7.x

jhodgdon’s picture

Status: Needs review » Fixed

This is now in 7.x too. Thanks!

And by the way, don't be alarmed about the test failure in #5. The test had stalled due to something weird on qa.drupal.org, and it finally got run after I had committed the patch, which is why it couldn't be applied.

jmarkel’s picture

Thanks. I'd wondered about the failed test - good to know it wasn't me :-)

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