*/ class CategoryEventSubscriber extends EntityManagerEventSubscriber { protected Slugify $slugify; public function __construct(Slugify $slugify) { $this->slugify = $slugify; } public function support(EntityInterface $entity) { return $entity instanceof Category; } public function onPreUpdate(EntityManagerEvent $event) { if (!$this->support($event->getEntity())) { return; } if ($event->getEntity()->getSlug()) { return; } $event->getEntity()->setSlug($this->slugify->slugify($event->getEntity()->getTitle())); } public function onPreCreate(EntityManagerEvent $event) { return $this->onPreUpdate($event); } }