Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony error in ResourceBundle HttpFoundationRequestHandler #876

Open
csabavirag opened this issue May 6, 2024 · 1 comment
Open

Symfony error in ResourceBundle HttpFoundationRequestHandler #876

csabavirag opened this issue May 6, 2024 · 1 comment
Labels
Bug Confirmed bugs or bugfixes.

Comments

@csabavirag
Copy link

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 NoResponseMate transferred this issue from Sylius/Sylius May 17, 2024
@NoResponseMate NoResponseMate added the Bug Confirmed bugs or bugfixes. label May 17, 2024
@NoResponseMate
Copy link
Contributor

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 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

No branches or pull requests

2 participants