Symfony3: is it possible to change the name of a form?

Roubi picture Roubi · May 3, 2016 · Viewed 16.8k times · Source

With Symfony 2.7, you could customize a form's name in your EntityType class with the method getName()
This is now deprecated. Is there another way to do that with Symfony 3.0 ?
I have custom prototype entry_rows for collections that I would need to use in different forms.
Since the name of the rows is based on the form's name, I would need to change the later in order to use them with a different form.

Answer

Matteo picture Matteo · May 3, 2016

You should implements the getBlockPrefix method instead of getName as described in the migration guide here.

As example:

/**
 * Returns the prefix of the template block name for this type.
 *
 * The block prefix defaults to the underscored short class name with
 * the "Type" suffix removed (e.g. "UserProfileType" => "user_profile").
 *
 * @return string The prefix of the template block name
 */
public function getBlockPrefix()
{
    return "form_name";
}

Hope this help