fix: handle request so errors can be displayed by jacquesbh · Pull Request #18936 · Sylius/Sylius
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/Sylius/Bundle/ShopBundle/Controller/ContactController.php`:
- Around line 79-94: The code after the form validation block in
ContactController references variables ($data, $contactEmail, $channel,
$redirectRoute) that are only set when the form is submitted and valid, causing
undefined variable errors on invalid submissions; move the sendContactRequest
and success redirect/flash logic so it executes only inside the if
($form->isSubmitted() && $form->isValid()) branch (where $data, $contactEmail,
$channel, $redirectRoute are defined) and leave invalid-form handling to render
the form with errors (do not call ContactEmailManager::sendContactRequest or
access $data['email'] outside the valid branch). Ensure
ContactEmailManager::sendContactRequest is only invoked from inside that valid
branch and that failure/error paths set appropriate flash/error responses or
re-render the form.
---
Nitpick comments:
In `@src/Sylius/Bundle/ShopBundle/Controller/ContactController.php`:
- Around line 49-56: In ContactController, the form handling block around the
POST branch (where $form->handleRequest($request); and the subsequent if
($form->isSubmitted() && $form->isValid()) { ... } lives) has inconsistent blank
lines and mixed indentation; normalize the block to use 4-space indentation
throughout, remove the stray blank line inside the POST handling, and align all
nested statements (including the /** `@var` mixed $data */, $data =
$form->getData(); and Assert::isArray($data);) to the same 4-space level so the
scope and formatting are consistent.