-
Notifications
You must be signed in to change notification settings - Fork 138
Not able to decorate a form type service #290
Comments
Can you find the commit that introduced that piece of code? Maybe there is a commit message that explains this ? |
commit 0bd414f fix deprecated notices by raibax. seens to be a important fix, still don't understand much, is there any other way for me to customize the registration form? I tried to extend the class and them aliasing the service, but them this same container didn't inject the dependencies. heres the config: <service id="sonata.user.registration.form.type" class="Application\Sonata\UserBundle\Form\RegistrationFormType">
<tag name="form.type" alias="sonata_user_registration" />
<argument>%fos_user.model.user.class%</argument>
<argument>%sonata.user.registration.form.options%</argument>
</service> heres the error:
my code is simple as this: use Sonata\UserBundle\Form\Type\RegistrationFormType as BaseRegitrationFormType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends BaseRegitrationFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('company');
}
} any sugestions? Btw, this extended class was working on Sonata Core Bundle 2.4@dev |
I have just solved my issue by doing the following: config.yml sonata_user:
profile:
register:
form:
type: sonata_user_registration_company
handler: sonata.user.registration.form.handler.default
name: sonata_user_registration_form service definition: <service id="sonata.user.registration.form.type.extension" class="Application\Sonata\UserBundle\Form\RegistrationFormType">
<tag name="form.type" alias="sonata_user_registration_company" />
<argument>%fos_user.model.user.class%</argument>
<argument>%sonata.user.registration.form.options%</argument>
</service> and my class: namespace Application\Sonata\UserBundle\Form;
use Sonata\UserBundle\Form\Type\RegistrationFormType as BaseRegitrationFormType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends BaseRegitrationFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('company');
}
//i had to override this method so i could change its alias on form.type tag
public function getBlockPrefix()
{
return 'sonata_user_registration_company';
}
} I guess that on my first try i got confused by the service aliasing and the form.type tag aliasing. Even tho i've solved my problem, i still couldn't use the service decoration wich is a elegant solution for this situation where one has to add fields into a existing form type. Thanks. |
I think you might be right. If you find a solution that does not trigger a deprecation warning and works with sf3, a PR will be very welcome! |
The class you are having problems with, got deprecated since this PR: #462 You can follow the docs to opt-out of using it. Closing because this is fixed with a workaround and with the correct way (disabling core form mapping) |
I needed to add a field to the registration form on sonata user bundle, and so i decided to decorate the service using the symfony service decoration feature like this:
but then i got this error:
looking into the code i got these lines in vendor/sonata-project/core-bundle/Form/Extension/DependencyInjectionExtension.php at line 103
by comenting these lines i got my form working, i dont know why to remove the symfony decoration mechanism with this code, i don't know what kind of bug this verification covers, but i love the decorator pattern and so i love this symfony feature, is there any way to remove or refactor this code to fix this issue?
I love this project by the way, it saves my life always.
By the way, this is my environment:
PHP 7.0.7
Symfony 2.8.6
Sonata Core Bundle 3.0.1
Sonata Admin Bundle 3.1.0
The text was updated successfully, but these errors were encountered: