2

I've read this: http://api.drupal.org/api/drupal/includes%21form.inc/function/batch_set/6 and through the source code, but I cannot see how a batch operation can flag that an error has occurred to show the error message.

I can set $context['finished'] = 1.0; to end the batch, but I cannot see how to set $current_set['success'] to FALSE to abort the batch and show the error message to the user.

How is this done? Is there a good example somewhere?

1 Answer 1

3

To set $current_set['success'] to FALSE, you can use the following code.

$current_set = &_batch_current_set();
$current_set['success'] = FALSE;

To set the messages to show to the users, you can use the following code.

$batch_context['results'][] = 'The error to be shown to the user';
$batch_context['finished'] = 1.0;

$batch_context is the last argument passed to the operation callback.

The "finished" callback receives $current_set['success'], and $batch_context['results'] respectively as first, and second argument. It can show the errors to the users using drupal_set_message().

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.