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