-
Notifications
You must be signed in to change notification settings - Fork 263
fix deprecated function in Select2Type #430
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
Conversation
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
public function getBlockPrefix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also keep getName()
? I think it's still needed for symfony 2.8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are needed only for Symfony <2.8
compatibility.
2.8 and 3.0 are the same, except the deprecation removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yep, that's probably why I dropped symfony 2.7 support 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, do I need to keep getName()
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, getName()
only exists until symfony 2.7 and we only support >=2.8.
But actually I don't really see how this type can work in Symfony3 at the moment. As it has to be referenced by FQCN now how would you distinguish choice
from hidden
? @davidzzz did you manage to make it work or are you just looking into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it in symfony 2.8. Here is my code
$builder->add('test', new Select2Type('entity'), array('label' => 'Test', 'class' => MyTestBundle:Test'));
Still get deprecation warning, but it works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, unfortunately this wouldn't work for Symfony 3.0, cf. the snipped below which is extracted from https://github.com/symfony/symfony/blob/master/UPGRADE-3.0.md :
Passing type instances to Form::add(), FormBuilder::add() and the FormFactory::create*() methods is not supported anymore. Pass the fully-qualified class name of the type instead.
Before:
$form = $this->createForm(new MyType());
After:
$form = $this->createForm(MyType::class);
So we can't use the current magic constructor to register different types from the same class anymore :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An option could be to switch to something like this instead : http://symfony.com/doc/current/cookbook/form/create_form_type_extension.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if I want to pass the object to the form, how can I do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of 3.0 you can only pass the class, it the form type needs an object it can be registered as a service.
I'll merge your PR for now, removing some deprecations doesn't hurt. But please look for alternatives, I'll probably deprecate this whole feature as there seems to be no simple fix for Symfony 3. If you want to "selectify" a choice type, you can just add a css class to it and have some js around.
No description provided.