#1984610: Convert user_pass to a new-style Form object showed us that you can't inject the request object into the form method.

Instead of manually using some reflection we can rely on the controller resolver which does all this fancy logic.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Needs review
FileSize
6.63 KB
ParisLiakos’s picture

Issue tags: +WSCCI

tagging

Crell’s picture

+++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
@@ -50,15 +50,16 @@ public function content(Request $request, $_form) {
+    // At the form and form_state to trick the getArguments method of the
+    // controller resolver.
+    $form_state = array();
+    $request->attributes->set('form', array());
+    $request->attributes->set('form_state', $form_state);
+    $args = $this->container->get('controller_resolver')->getArguments($request, array($form_object, 'buildForm'));
+    unset($args[0], $args[1]);
+    $request->attributes->remove('form');

I'm not sure I'd even bother removing form and form_state at the end. It doesn't hurt anything, does it?.

Otherwise, I like this cleanup.

dawehner’s picture

I hope noone has the idea to put 'form' into the request attributes manually.

Crell’s picture

Mm, true, that would cause a problem. Effectively then we just blacklist those two variable names. Are we OK doing that?

dawehner’s picture

FileSize
806 bytes
6.51 KB

Let's agree on that.

Status: Needs review » Needs work

The last submitted patch, drupal-1998166-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review

Let us go with #1 because it is safer.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

#1 is RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal-1998166-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
6.63 KB

Just reupload the one in #1

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

This removes a HUGE DrupalWTF in that half of controllers can get Request $request, but not forms.

tim.plunkett’s picture

#11: drupal-1998166-11.patch queued for re-testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 040ff57 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.