Symfony-docs: FormTypeInterface::getName() is deprecated

Created on 1 Aug 2015  路  8Comments  路  Source: symfony/symfony-docs

As of Symfony 2.8, implementing the getName() method of the FormTypeInterface() is deprecated. Instead, form types should be referenced by their FQCN (which is quite easy as PHP supports the class constant since 5.5). Additionally, you should now also not use the alias attribute anymore when tagging your services as a form type using the form.type tag.

More detailed information and examples can be found in the code PR (see symfony/symfony#15079) which has just been merged.

Form actionable hasPR

Most helpful comment

@stof Thanks for your answer. I wanted to change what is now called blockPrefix. I had an answer on StackOverflow, it looks like getName() has been replaced with getBlockPrefix().
My problem was I have two forms: formA with field myCollection, and formB, which also has a field myCollection. So in my custom prototype form, if I write a block like _formA_myCollection_entry_row, it won't be recognized when I call my formB, because this time it will be called _formB_myCollection_entry_row. By changing the form's name, I don't have to duplicate my prototype entry_row.

All 8 comments

Given that Symfony 2.8 is designed for PHP 5.3.9 and up, docs should display both the short ::class examples and the long/verbose alternatives for 5.3 and 5.4.

Indeed, that's a good hint, Javier!

Please see #5909, for the second set of huge changes for this :)

Does this mean you can't customize a form's name anymore ? I have custom prototype entry_rows for some collections that I would need to use from different forms, so I need to change the form's name.

@pfleu I think you are confusing the form name and the form type name

@stof Thanks for your answer. I wanted to change what is now called blockPrefix. I had an answer on StackOverflow, it looks like getName() has been replaced with getBlockPrefix().
My problem was I have two forms: formA with field myCollection, and formB, which also has a field myCollection. So in my custom prototype form, if I write a block like _formA_myCollection_entry_row, it won't be recognized when I call my formB, because this time it will be called _formB_myCollection_entry_row. By changing the form's name, I don't have to duplicate my prototype entry_row.

@pfleu your question is logical. But the block prefix is not the same as the name, note that the usage of the name has been deprecated in many function call in favor of the FQCN.

You can also change the block prefix used in templates dynamically by using the option block_name.

Hope that helps, cheers!

@HeahDude Thanks for your explanations!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samjarrett picture samjarrett  路  4Comments

x8core picture x8core  路  4Comments

steevanb picture steevanb  路  4Comments

wouterj picture wouterj  路  4Comments

javiereguiluz picture javiereguiluz  路  3Comments