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.

Issue fork drupal-2860627

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

scott_euser created an issue. See original summary.

markdorison’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs review » Active

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Active » Closed (won't fix)
Issue tags: +Bug Smash Initiative

Looking at the code for callback_batch_finished, it returns a void. I don't see anything to fix here. Re-open if I am wrong.

Thanks

scott_euser’s picture

Version: 9.4.x-dev » 9.5.x-dev
Category: Bug report » Task
Status: Closed (won't fix) » Active

Looking back at this issue, I think my point was that form.api.php is code which serves as a sort of documentation for what https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/includes/bat... allows you to do. It however does not indicate that you are allowed to return a RedirectResponse, yet that above function shows that you can actually return a RedirectResponse and it will redirect the user after the batch processing is finished.

So there is a nice feature that is useful for developers, yet the documentation does not explain that that feature exists. You need to spot it yourself in the _batch_finished() function.

Comparatively, the `batch_process()` function does explain this as a possibility.

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

I would be happy to put this into a merge request.

joachim’s picture

Version: 9.5.x-dev » 11.x-dev
Category: Task » Bug report
Issue tags: +Novice

> 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.

akshaydalvi212 made their first commit to this issue’s fork.

diederik.beirnaert made their first commit to this issue’s fork.

diederik.beirnaert’s picture

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());
    }
joachim’s picture

Status: Active » Needs work

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

diederik.beirnaert’s picture

Did the codestyle fixes Joachim suggested.

diederik.beirnaert’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.21 KB

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.

diederik.beirnaert’s picture

Status: Needs work » Needs review

moved comment that was placed after line of code.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new681 bytes

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.