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

Created on 14 March 2017, almost 8 years ago
Updated 19 June 2024, 6 months 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.
  • diederik.beirnaert β†’ made their first commit to this issue’s fork.

  • Pipeline finished with Failed
    7 months 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 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

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

  • Pipeline finished with Failed
    6 months ago
    Total: 162s
    #201842
  • Did the codestyle fixes Joachim suggested.

  • Status changed to Needs review 6 months ago
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 6 months ago
  • moved comment that was placed after line of code.

  • Pipeline finished with Failed
    6 months ago
    Total: 575s
    #202603
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.71.5 2024