idea-php-symfony2-plugin icon indicating copy to clipboard operation
idea-php-symfony2-plugin copied to clipboard

False positive "Symfony: Create a form view for passing to template" when using `renderForm`

Open SVillette opened this issue 2 years ago • 3 comments

Description

Since Symfony 5.3, a controller can call the method renderForm and doesn't have to create the FormView when passing a FormInterface to a template.

When using this method (So I not calling $form->createView() when passing $form to the template), I have a warning Symfony: Create a form view for passing to template.

image

PhpStorm version: 2022.1, build #PS-221.5080.224 PhpStorm Symfony plugin version: 2022.1.221

SVillette avatar Apr 22 '22 06:04 SVillette

Same here, BTW when:

    ...
    'form' => $form->createView()
    ...

the message is gone, but Symfony error occurs: Passing a FormView to "App\Controller\FooController::renderForm()" is not supported, pass directly the form instead for parameter "form". Update: see @tip2tail below for Symfony 6.

czachor avatar Apr 29 '22 09:04 czachor

As a workaround, you can disable inspection for Symfony: Create a form view for passing to template

In Settings > Editor > Inspection search for "Symfony"

Erdou avatar Jun 06 '22 09:06 Erdou

renderForm has been deprecated in Symfony 6 now, and you should be able to pass the form object direct to render - so another case that needs to be catered for on this issue.

tip2tail avatar Dec 19 '22 23:12 tip2tail