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.
I lost a couple of hours because I wrote this:
$operations[] = array('callback_function');
$batch['operations'] = $operations;
Instead of this:
$operations[] = array('callback_function', array());
$batch['operations'] = $operations;
And couldn't work out why my batch operation was only being called once despite setting $context['finished'] = 0.5
in the callback function.
Turns out, if you omit the array()
parameter, the $context
variable passed to the callback function will be uninitialised. Attached is a simple patch that would detect this situation and make the array of arguments in the operation definition optional if none are required.
Comment | File | Size | Author |
---|---|---|---|
batch-operation-optional-args.patch | 482 bytes | Draknek | |