Description
In this episode, you'll learn how to leverage Sylius’s resource controller event system to react to actions like updating an entity – without touching the controller logic itself.
Sylius automatically dispatches pre_* and post_* events for every CRUD action (e.g. sylius.brand.pre_update). Using these events, you can:
- Modify entity data before saving (e.g. auto-update the updatedAt timestamp),
- Block invalid updates based on business rules (e.g. prevent updating a disabled brand),
- Stop propagation and change the HTTP response (e.g. redirect if brand name is "forbidden brand"),
- Show custom flash messages to the user.
During this episode:
- You’ll learn how to inspect events using the Symfony Profiler,
- You’ll create an EventSubscriber that listens to sylius.brand.pre_update,
- You’ll see how events help enforce business logic cleanly and maintainably.
This episode demonstrates one of Sylius’s most powerful mechanisms – event-driven customization, allowing you to extend functionality without cluttering your controller code.