em = $entityManager; $this->merchantResolver = $merchantResolver; $this->sectionResolver = $sectionResolver; } public static function getSubscribedEvents() { return [ EntityManagerEvent::CREATE_EVENT => ['createEntity'], ]; } public function createEntity(EntityManagerEvent $event) { $entity = $event->getEntity(); $entityRepository = $this->em->getRepository(get_class($entity)); if ($entity instanceof FilterSectionInterface) { $this->setSectionProperty($entity, $entityRepository); } if ($entity instanceof FilterMerchantInterface) { $this->setMerchantProperty($entity, $entityRepository); } if ($entity instanceof FilterMultipleMerchantsInterface) { $this->setMultipleMerchantProperty($entity, $entityRepository); } } private function setSectionProperty($entity) { $entity->setSection($this->sectionResolver->getCurrent()); } private function setMerchantProperty($entity) { $entity->setMerchant($this->merchantResolver->getCurrent()); } private function setMultipleMerchantProperty($entity) { if ($entity->getMerchants()->isEmpty()) { $entity->addMerchant($this->merchantResolver->getCurrent()); } } }