[regression] Form redirects are lost when the form is cached

Created on 4 October 2016, almost 9 years ago
Updated 18 August 2025, 5 days ago

Problem/Motivation

In D7, form_state_defaults() defined which properties were cacheable. It included 'redirect'.
In #2225353: Convert $form_state to an object and provide methods like setError() β†’ , $form_state was converted to an array, and \Drupal\Core\Form\FormState::getCacheableArray() now defines these properties.

In the original conversion, 'redirect' was swapped for 'response'.
This was correct, 'response' should have been added in addition.

The result of this mistake is that any calls to $form_state->setRedirect() in an implementation of FormInterface::buildForm() will be ignored.
This is mitigated because most forms correctly set their redirects in FormInterface::submitForm()

An example of one that does not is \Drupal\language\Form\NegotiationSessionForm. This was converted from a system_settings_form() implementation, which usually didn't have custom #submit callbacks, so the builder would set the redirect.

Proposed resolution

Ensure any redirects set are cached with the form.

Remaining tasks

N/A

User interface changes

N/A

API changes

Not really?

Data model changes

N/A

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

forms system

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Since there has been no activity here for over 8 years we are asking if this problem persists on a currently supported version of Drupal. To help, add a comment explaining if the problem still occurs or not. Any extra detail you can provide can help others who experienced this.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
    Thanks!

Production build 0.71.5 2024