public function save(WrappedEntity $wrappedEntity, Component $component, Mapper $mapper)
 {
     if (!$this->canHandle($component, $wrappedEntity)) {
         return FALSE;
     }
     $value = NULL;
     if ($component instanceof IControl) {
         if ($component->isOmitted()) {
             return TRUE;
         }
         $value = $component->getValue();
     } elseif ($component instanceof Container) {
         $value = $component->getValues(TRUE);
     }
     $mapping = $wrappedEntity->getMetadata()->getFieldMapping($component->name);
     if ($value === "" && $mapping['nullable'] && in_array($mapping['type'], self::$numberTypes)) {
         $value = NULL;
     }
     $mapper->execute(function () use($wrappedEntity, $component, $value) {
         $wrappedEntity->setValue($component->name, $value);
     });
     $mapper->runValidation(function (ValidatorInterface $validator) use($wrappedEntity, $component, $value) {
         return $validator->validatePropertyValue($wrappedEntity->getEntity(), $component->name, $value);
     }, $component);
     return TRUE;
 }
 public function save(WrappedEntity $wrappedEntity, Component $component, Mapper $mapper)
 {
     if (!$component instanceof Container && !$component instanceof IControl) {
         return FALSE;
     }
     if ($component instanceof MultiChoiceControl) {
         return FALSE;
     }
     $meta = $wrappedEntity->getMetadata();
     if (!($association = $this->getAssociationMetadata($meta, $component->name))) {
         return FALSE;
     }
     if ($component instanceof Container) {
         $relatedEntity = $this->getRelatedEntity($wrappedEntity, $component, $association);
         if ($relatedEntity) {
             $mapper->saveValues($component, $relatedEntity);
             $mapper->execute(function () use($wrappedEntity, $component, $relatedEntity) {
                 $wrappedEntity->getEntityManager()->persist($relatedEntity);
                 $wrappedEntity->setValue($component->getName(), $relatedEntity);
             });
             $mapper->runValidation(function (ValidatorInterface $validator) use($wrappedEntity, $component, $relatedEntity) {
                 return $validator->validatePropertyValue($wrappedEntity, $component->getName(), $relatedEntity);
             }, $component->getForm());
         }
     } elseif ($component instanceof IControl) {
         if ($component->isOmitted()) {
             return TRUE;
         }
         $value = $component->getValue() ?: NULL;
         if ($wrappedEntity->hasAssociation($component->name) && $value && !is_object($value)) {
             $association = $wrappedEntity->getMetadata()->getAssociationMapping($component->name);
             $repository = $wrappedEntity->getEntityManager()->getRepository($association['targetEntity']);
             $value = $repository->find($value);
         }
         $mapper->execute(function () use($wrappedEntity, $component, $value) {
             $wrappedEntity->setValue($component->name, $value);
         });
         $mapper->runValidation(function (ValidatorInterface $validator) use($wrappedEntity, $component, $value) {
             return $validator->validatePropertyValue($wrappedEntity->getEntity(), $component->name, $value);
         }, $component);
     }
     return TRUE;
 }
 public function process()
 {
     if ($this->component instanceof IControl && $this->component->isOmitted()) {
         return;
     }
     $data = $this->component instanceof MultiChoiceControl ? $this->component->getValue() : $this->component->getValues(TRUE);
     $associationMapping = $this->wrappedEntity->getMetadata()->getAssociationMapping($this->component->name);
     $this->type = $associationMapping['type'];
     $targetEntityMetadata = $this->entityManager->getClassMetadata($associationMapping['targetEntity']);
     $this->processIdentifier($targetEntityMetadata);
     $this->prepareCollection();
     $targetEntityRepository = $this->entityManager->getRepository($associationMapping['targetEntity']);
     foreach ($data as $rowKey => $row) {
         $newEntity = NULL;
         if (is_array($row)) {
             $values = $this->getIdentifierValues($row);
             if ($values && !($newEntity = $this->popByIdentifier($values)) && $this->type == ClassMetadata::MANY_TO_MANY) {
                 $newEntity = $targetEntityRepository->findOneBy($values);
             }
             if (!$newEntity) {
                 $newEntity = $targetEntityMetadata->newInstance();
             }
             $this->mapper->saveValues($this->component[$rowKey], $newEntity);
         } elseif ($row) {
             $currentValue = $this->component instanceof MultiChoiceControl ? $row : $rowKey;
             if (!$this->popByIdentifier([$currentValue])) {
                 $newEntity = $targetEntityRepository->find($currentValue);
             }
         }
         if ($newEntity) {
             $this->addEntity($newEntity);
         }
     }
     foreach ($this->forRemoval as $entityForRemove) {
         $this->collection->removeElement($entityForRemove);
     }
     $this->mapper->execute(function () {
         $this->updateCollection();
     });
     $this->validate();
 }
 public function save(WrappedEntity $wrappedEntity, Component $component, Mapper $mapper)
 {
     if (!$this->canHandle($component, $wrappedEntity)) {
         return FALSE;
     }
     /** @var TextBase $component */
     if ($component->isOmitted()) {
         return TRUE;
     }
     $mapping = $wrappedEntity->getMetadata()->getFieldMapping($component->getName());
     $value = $component->getValue();
     if (is_string($value)) {
         $format = $component->getOption('date-format');
         $type = $this->convertMappingToAdapterType($mapping['type']);
         $value = $this->adapter->parse($value, $type, $format);
     }
     $mapper->execute(function () use($wrappedEntity, $component, $value) {
         $wrappedEntity->setValue($component->name, $value);
     });
     $mapper->runValidation(function (ValidatorInterface $validator) use($wrappedEntity, $component, $value) {
         return $validator->validatePropertyValue($wrappedEntity->getEntity(), $component->name, $value);
     }, $component);
     return TRUE;
 }