I want to edit the creation of a customer, I want to add a field during the creation. During the creation the service "sylius.controller.customer:createAction" is called in security.yml
sylius_shop_register:
path: /register
methods: [GET, POST]
defaults:
_controller: sylius.controller.customer:createAction
_sylius:
template: "@SyliusShop/register.html.twig"
form: Sylius\Bundle\CoreBundle\Form\Type\Customer\CustomerRegistrationType
event: register
redirect:
route: sylius_shop_account_dashboard
flash: sylius.customer.register
However I checked a lot of sylius services I didn't find it. How can I acces to this service to custom the creation ?
Thanks for your time.
You should customize the form and not the controler. You can find detailed information here (sylius customizing form)
The idea is:
Create a form extension:
final class CustomerRegistrationType extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Adding new fields works just like in the parent form type.
$builder->add('YourField', TextType::class, [
'required' => false,
'label' => 'app.form.customer.yourfield',
]);
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return CustomerRegistrationType::class;
}
}
Register this extension as a service in the AppBundle/Resources/config/services.yml
Add according translations, and add a new template to show your new field
Regards