I have a batch process which involves a series of functions that result in an array of data. I would like to return this array to a function that will build output a themed page, upon success of the batch.

My batch works correctly (it creates the array of data that I need)
My menu callback functions correctly (I can render basic data by calling the menu item)

However, I cannot see how to return my array of data to the menu callback on success of the batch.

I 'think' my batch_finished function should look like:

function cobie_report_batch_finished($success, $results, $operations) {
  if ($success) {
        cobie_report_page($output); //cobie_report_page is the menu_callback
  } else {
    drupal_set_message(t('An error occurred');

What I can't seem to figure out is:

1. The menu callback (cobie_report_page) won't fire on success of the batch.
2. How can I pass the data array from the final function of the batch to cobie_report_batch_finshed? I've tried using $contact['sandbox']['output'], but $context doesn't seem accessible in the _finished function.

Any help would be great. I feel like I'm close, but can't make the final step.



OK. I've solved part of my problem.

I can return the results of my functions by setting $context['results'] to the array of data constructed by the functions in my batch. These I can then access in the _finished function by $results.

However, when I try to fire the function to create the page, it doesn't execute.

cobie_report_page($results) is what is called in the _finished function of the batch. This calls:

function cobie_report_page($output) {
$render_array = array(
'#theme' => 'cic_report', // The theme function to apply to the #items
'#items' => $output, // The $results array passed in through $output.
'#title' => t('CIC Report'),
return $render_array;

So, what have I missed?

I've solved some of my problem, but perhaps not in the best way.

I realised that the way to call the menu item would be to use drupal_goto, so that I can now access the menu callback. I am passing the data array by creating a session variable and then passing this into a render_array.

Is there a better way?