Description
In this episode, you’ll learn how to add a custom field to a Sylius admin grid – using a dynamic field that displays the number of products assigned to each brand.
You’ll learn:
- When to build your own field type instead of using built-in types (string, datetime, twig, etc.),
- How to implement a field type class with the FieldTypeInterface,
- How to dynamically fetch and display data based on relations (e.g. number of related products),
- How to register your custom field as a Symfony service and tag it with sylius.grid.field,
- How to use your new field type in YAML grid configuration (sylius_grid.yaml).
Final result:
- A dynamic field appears in the brand grid, showing product counts per brand,
- The interface becomes more informative and contextual, reducing the need to open other views,
- The solution follows Sylius architecture and can be extended with APIs or advanced business logic.