em = $entityManager; } public static function getSubscribedEvents() { return [ EntityComponentEvent::DUPLICATE_EVENT => ['duplicateAddressOnDuplicateEvent'], ]; } public function duplicateAddressOnDuplicateEvent(EntityComponentEvent $event) { $entity = $event->getEntity(); $classMetadata = $this->em->getClassMetadata(get_class($entity)); foreach ($classMetadata->getAssociationMappings() as $associationMapping){ if(in_array(AddressInterface::class, class_implements($associationMapping['targetEntity']))){ $methodGet = 'get'.ucfirst($associationMapping['fieldName']); $methodSet = 'set'.ucfirst($associationMapping['fieldName']); if(method_exists($entity, $methodGet) && method_exists($entity, $methodSet)){ $newAddress = clone $entity->$methodGet(); $entity->$methodSet($newAddress); $this->em->create($newAddress, false); } } } } }