Documentation for batch api callback_batch_finished() doesn't say that a RedirectResponse can be returned.

Created on 14 March 2017, over 7 years ago
Updated 14 May 2024, about 1 month ago

API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21fo...

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

While batch_process does indicate that a RedirectResponse can be returned, callback_batch_finished does not but the code for it indicates that it is possible to redirect a RedirectResponse (and it works as such).

    // Determine the target path to redirect to. If a batch 'finished' callback
    // returned a redirect response object, use that. Otherwise, fall back on
    // the form redirection.
    if (isset($batch_finished_redirect)) {
      return $batch_finished_redirect;
    }

I would suggest we update it to match batch process by adding the following:

Return value
\Symfony\Component\HttpFoundation\RedirectResponse|null A redirect response if the batch is progressive. No return value otherwise.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
DocumentationΒ  β†’

Last updated 1 day ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom scott_euser

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > redirect response if the batch is progressive. No return value otherwise.

    I'm not sure what a *progressive* batch is.

    The docs should say that a RedirectResponse *may* be returned, to send the user to a page other than the default batch results page.

    They should also say that if there are multiple batch sets, only the last redirect is used:

            // If a batch 'finished' callback requested a redirect after the batch
            // is complete, save that for later use. If more than one batch set
            // returned a redirect, the last one is used.
    

    It would be nice also if the sample code had a redirect added to it, e.g.:

          return new RedirectResponse(Url::fromRoute('my.batch.results')->toString());
    

    Tagging as novice, updating version, and setting to bug report as this is missing documentation.

  • First commit to issue fork.
  • Pipeline finished with Failed
    about 1 month ago
    Total: 193s
    #172222
  • Updated documentation for callback_batch_finished to include RedirectResponse.
    And added an example:

    // Optionally, redirect if needed.
        if (shouldRedirect()) {  // Assume shouldRedirect() is a function that determines if a redirect is necessary.
          return new \Drupal\Core\Routing\RedirectResponse(\Drupal\Core\Url::fromRoute('example.route')->toString());
        }
    
  • Status changed to Needs work about 1 month ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Nearly there -- looks good overall, just a few formatting fixes needed.

Production build 0.69.0 2024