Skip to content

Commit 3db80ca

Browse files
committed
pass $data as second parameter
1 parent 4b7271a commit 3db80ca

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,21 @@ protected function stream(string $view, array $parameters = [], StreamedResponse
297297
* * if the form is submitted but invalid, $render is called and a 422 HTTP status code is set if the current status hasn't been customized
298298
* * if the form is submitted and valid, $onSuccess is called, usually this method saves the data and returns a 303 HTTP redirection
299299
*
300-
* @param callable(FormInterface): Response $onSuccess
301-
* @param callable(FormInterface): Response $render
300+
* @param callable(FormInterface, mixed): Response $onSuccess
301+
* @param callable(FormInterface, mixed): Response $render
302302
*/
303303
public function handleForm(FormInterface $form, Request $request, callable $onSuccess, callable $render): Response
304304
{
305305
$form->handleRequest($request);
306306

307307
$submitted = $form->isSubmitted();
308+
309+
$data = $form->getData();
308310
if ($submitted && $form->isValid()) {
309-
return $onSuccess($form);
311+
return $onSuccess($form, $data);
310312
}
311313

312-
$response = $render($form);
314+
$response = $render($form, $data);
313315
if ($submitted && 200 === $response->getStatusCode()) {
314316
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
315317
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,10 @@ public function testHandleFormNotSubmitted()
433433
$response = $controller->handleForm(
434434
$form,
435435
Request::create('https://example.com'),
436-
function (FormInterface $form): Response {
436+
function (FormInterface $form, $data): Response {
437437
return new RedirectResponse('https://example.com/redir', Response::HTTP_SEE_OTHER);
438438
},
439-
function (FormInterface $form): Response {
439+
function (FormInterface $form, $data): Response {
440440
return new Response('rendered');
441441
}
442442
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy