Stop using getMainRequest() to build $form['#action']

Created on 12 June 2015, about 9 years ago
Updated 17 February 2024, 7 months ago

Problem/Motivation

Quoting @dawehner from #2263569-244: Bypass form caching by default for forms using #ajax. β†’ :

To be clear, using the master request is almost always semantically the wrong thing to do

We currently use the master request to populate $form['#action'] in \Drupal\Core\Form\FormBuilder::buildFormAction().

Using getCurrentRequest() caused test failures in \Drupal\system\Tests\Form\RedirectTest, but continuing to use the master request with <current> caused failures in \Drupal\system\Tests\System\AccessDeniedTest

This is due to conflicting use cases covered by RedirectTest and AccessDeniedTest. The latter asserts that people are sent to the original destination after a login while the former tests that it is possible for a form to set a redirect destination (even on exception pages).

The problem is that in HEAD the destination query parameter is used to pass the original location into the subrequest where the exception is rendered. However, the destination parameter always overrides any redirect set during form building. Usage of the master request in the FormBuilder does not really resolve that conflict but actually hides it.

Proposed resolution

Do not use the destination parameter in order to pass the original location to the subrequest but rather a deticated one (_exception_location).

Remaining tasks

Review.

User interface changes

N/A

API changes

TBD

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated less than a minute ago

Created by

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

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

Production build 0.71.5 2024