How do you do a redirect after a batch job? I'm working on setting up a batch process in Drupal 8 that will gather a bunch of remote information for a collection of entities, cache it, and create a list of the results on its own page. The batch process is kicked off from a form using batch_set().

The batch job runs fine, but I'm not sure how to do the redirect at the end. Since Drupal 8 uses RedirectResponse objects or $this-&gt;redirect('user.page'); in a controller and the callback for a batch job doesn't have a return type, I'm not sure what to use to trigger the redirect.

I've tried using the url_options value of the batch job definition but that's not working.

$batch = [
  'title'    =&gt; $this-&gt;t('job running'),
  'init_message' =&gt; $this-&gt;t('starting job'),
  'operations'  =&gt; $ops,
  'finished' =&gt; '\Drupal\my_module\MyClass::finished',
  'url_options' =&gt; [
    'query' =&gt; [
      'destination' =&gt; '/job/results',
    ],
  ],
];
Apparently I needed to ask to see the answer: return a RedirectResponse from the finish callback:

public static function finished($success, $results, $operations) {
  if ($success) {
    // Here we do something meaningful with the results.
    $message = t("@count tasks were done.", array(
      '@count' =&gt; count($results),
    ));
    drupal_set_message($message);
  }

  return new RedirectResponse('/job/results');
}


As far as I can tell this is an undocumented behavior.

From the helpful comment below, you can also add batch_redirect on the batch array that's either a string or Url object:

$batch = [
  'title'    =&gt; $this-&gt;t('job running'),
  'init_message' =&gt; $this-&gt;t('starting job'),
  'operations'  =&gt; $ops,
  'finished' =&gt; '\Drupal\my_module\MyClass::finished',
  'batch_redirect' =&gt; '/job/results',
];