Skip to content

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

Merged
merged 1 commit into from
Jul 1, 2016
Merged

Conversation

davidzzz
Copy link

No description provided.

}

/**
* {@inheritdoc}
*/
public function getName()
public function getBlockPrefix()
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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 😃

Copy link
Author

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?

Copy link
Collaborator

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?

Copy link
Author

@davidzzz davidzzz Jun 30, 2016

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.

Copy link
Collaborator

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 :/

Copy link
Collaborator

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

Copy link
Author

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?

Copy link
Collaborator

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.

@bamarni bamarni merged commit 459bd9e into genemu:master Jul 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy