Skip to content

[Form] [2.8] Naming forms works only in some cases; passing extra params to a form #16296

@petforsberg

Description

@petforsberg

1.

There's a new way to naming forms with help of getBlockPrefix() method, according to the upgrade info https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md.

The problem is it works only when Forms are instantiated e.g.:

 new MyFormType()

But not by a class name, e.g.:

 'AppBundle/MyFormType'

In the second case, I get the form name like 'my_form' regardless whatever I put into the getBlockPrefix() or getName() methods. But when I pass to the Form Factory an instance of my form type (e.g. new MyFormType() as shown above ), the generated form has the proper block prefix - the one I set, e.g. 'profile' in the example from the upgrade text file:

class UserProfileType extends AbstractType
{
   public function getBlockPrefix()
   {
       return 'profile';
   }
}

2.

It seems that when one tries to create a form in a new way (with a class), it seems there's no any possibility to pass any parameters to its constructor.
Maybe introducing some extra array param to the Form Factory when creating a form from a class would resolve the issue?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions