feature/formΒΆ

DescriptionΒΆ

This feature extends the default UserFormType used in Lodel to introduce a new civility field and customize form submission behavior β€” without altering the original form class or template.

It adds:

  • A new unmapped radio field called civility with choices: Mr., Mrs., Miss or none

  • An event subscriber that listens to the PRE_SUBMIT phase and prepends the selected civility to the user’s last name

The extension is seamlessly integrated into the existing form and does not require any manual template updates or controller changes.

File structureΒΆ

HelloWorldBundle/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ EventSubscriber/
β”‚   β”‚   └── UserFormSubmitSubscriber.php         # Modifies form data during the PRE_SUBMIT event
β”‚   └── Form/
β”‚       └── UserFormTypeExtension.php            # Extends the original UserFormType to add the "civility" field
β”‚   └── Resources/
β”‚       └── config/
β”‚           └── services.yaml                    # Declares and tags the form extension and subscriber

Internal ImplementationΒΆ

This feature is composed of the following elements:

  • Form Type Extension (UserFormTypeExtension): Adds a civility radio field (unmapped) to the form and attaches the custom event subscriber.

  • Event Subscriber (UserFormSubmitSubscriber): Listens to FormEvents::PRE_SUBMIT and prepends the selected civility to the submitted lastName field.

  • Service Configuration (services.yaml): Registers the form type extension and event subscriber with the appropriate tags for Symfony to recognize and apply them automatically.

How to useΒΆ

You will see the additional "Civility" field appear, and it will automatically influence the submitted lastName without any modification to the original form or template.