Sylius / SyliusResourceBundle

Simpler CRUD for Symfony applications
https://sylius.com
MIT License
219 stars 155 forks source link

Symfony error in ResourceBundle HttpFoundationRequestHandler #876

Closed csabavirag closed 3 months ago

csabavirag commented 5 months ago

Sylius version affected: 1.13.0

Installed Sylius packages
# composer show |grep sylius
sylius-labs/association-hydrator              1.2.1  Doctrine ORM hydration performance optimization made easier.
sylius-labs/doctrine-migrations-extra-bundle  0.2.0 
sylius-labs/polyfill-symfony-event-dispatcher 1.2.0  Symfony EventDispatcher Polyfill
sylius-labs/polyfill-symfony-framework-bundle 1.1.1  Symfony FrameworkBundle Polyfill
sylius-labs/polyfill-symfony-security         1.1.2  Symfony Security Polyfill
sylius/calendar                               0.5.0  Date handling for PHP applications.
sylius/fixtures-bundle                        1.8.0  Configurable fixtures for Symfony applications.
sylius/grid-bundle                            1.12.1 Amazing grids with support of filters and custom fields integrated into Symfony.
sylius/mailer-bundle                          2.0.0  Mailers and e-mail template management for Symfony projects.
sylius/registry                               1.6.0  Services registry.
sylius/resource-bundle                        1.10.3 Resource component for Sylius.
sylius/sylius                                 1.13.0 E-Commerce platform for PHP, based on Symfony framework.
sylius/theme-bundle                           2.3.0  Themes management for Symfony projects.

Description
I use some parts of the Sylius package including the PaymentBundle. I have the following simple test controller created on the top of Docker sample of Symfony 6.4.7.

    #[Route('/test', name: 'app_test')]
    public function index(Request $request): Response
    {
        $form = $this->createForm(\Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodChoiceType::class, null, [
            'expanded' => true,
            'csrf_protection' => false,
        ]);
        $form->handleRequest($request);

        return $this->render('test.html.twig', [
            'form' => $form,
        ]);
    }

while test.html.twig is a simple

{% extends "base.html.twig" %}

{% block body %}
{{ form_start(form) }}
<input type=submit>
{{ form_end(form) }}
{% endblock %}

I added 2 payment method to the database which is displayed properly when visiting /test URL. image

However if I submit the form, I get the following error: image

Steps to reproduce

Possible Solution
If I change this line in \Sylius\Bundle\ResourceBundle\Form\Extension\HttpFoundation\HttpFoundationRequestHandler, the error goes away and it works as expected.

            } elseif ($request->request->has($name) || $request->files->has($name)) {
                /** @psalm-var array|null $default */
                $default = $form->getConfig()->getCompound() ? [] : null;

                if ($request->request->has($name)) {
-                    $params = $request->request->all($name);
+                    $params = $request->request->all()[$name];
                } else {
                    $params = $default;
                }

                $files = $request->files->get($name, $default);
            } else {

Since this part of the code has not been changed for some time, it might work for others but me?? Is there something I missed in terms of configuration?

NoResponseMate commented 4 months ago

Hi @csabavirag 👋

I've transferred the issue since ResourceBundle directly causes it.

Just checked and it indeed seems like a bug, quite possibly more places within the handler can cause the same issue. We'll have it fixed in the next 1.10 release.

Cheers 🍻