Do not allow form builder functions to return Response objects

Created on 24 October 2014, over 10 years ago
Updated 17 March 2025, 20 days ago

Problem/Motivation

Currently FormBuilder::retrieveForm() examines the result returned by a form builder function. If it is a response, it will send it to the browser and exit. As per #2230121: Remove exit() from FormBuilder β†’ this behavior is incompatible with the HTTP kernel because it gives any form whether it is rendered in the main content area or in a block the power to completely break the normal request/response flow.

Proposed resolution

Trigger a E_USER_DEPRECATED when form builder methods return response objects and fix affected forms in core - instead having them throw a EnforcedResponseException.
Add a EnforcedResponseException::redirectToUrl factory method to simplify this process

Remaining tasks

Get tests green
Reviews
Change notice
Release notes snippet

User interface changes

API changes

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

forms system

Created by

πŸ‡¨πŸ‡­Switzerland znerol

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

    Adding a EnforcedResponseException::redirectToUrl factory would also make it easier to redirect from inside the form method of an entity form. Returning a response is not possible from that method, it leads to a fatal error so already an EnforcedResponseException needs to be thrown there.

Production build 0.71.5 2024