*/ class NavigationEventSubscriber extends EntityManagerEventSubscriber { public function __construct( protected EntityManager $entityManager, protected CodeSlugify $slugify ) { } public function supports(EntityInterface $entity): bool { return $entity instanceof Navigation; } public function onPreUpdate(EntityManagerEvent $event) { if (!$this->supports($event->getEntity())) { return; } $menu = $event->getEntity(); $menu->setCode($this->slugify->slugify($menu->getCode())); } public function onPreCreate(EntityManagerEvent $event) { return $this->onPreUpdate($event); } }