Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof Nette\Forms\Container) {
         return FALSE;
     }
     if (!($relation = $this->getRelation($meta, $entity, $component->getName()))) {
         return FALSE;
     }
     $this->mapper->load($relation, $component);
     return TRUE;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof ToManyContainer) {
         return FALSE;
     }
     if (!($collection = $this->getCollection($meta, $entity, $name = $component->getName()))) {
         return FALSE;
     }
     $em = $this->mapper->getEntityManager();
     $UoW = $em->getUnitOfWork();
     $component->bindCollection($entity, $collection);
     foreach ($collection as $relation) {
         if ($id = $UoW->getSingleIdentifierValue($entity)) {
             $this->mapper->load($relation, $component[$id]);
             continue;
         }
         $this->mapper->load($relation, $component[ToManyContainer::NEW_PREFIX . $collection->indexOf($relation)]);
     }
     return TRUE;
 }
Exemple #3
0
 /**
  * @return \Venne\Forms\IFormFactory
  */
 public function create()
 {
     $form = parent::create();
     $form['_eventControl'] = $eventControl = new EventControl('_eventControl');
     $eventControl->onAttached[] = function () use($form) {
         $this->entityMapper->load($this->entity, $form);
         unset($form['_eventControl']);
     };
     $form->onSuccess[] = function (Form $form) {
         $this->entityMapper->save($this->entity, $form);
         $saveEntity = $this->saveEntity;
         if ($saveEntity && $saveEntity($form)) {
             try {
                 $this->entityMapper->getEntityManager()->flush($this->entity);
             } catch (\Exception $e) {
                 Debugger::log($e);
                 $form->addError($e->getMessage());
             }
         }
     };
     return $form;
 }
 public function buildField($name)
 {
     if (count($relation = explode('.', $name, 2)) == 2) {
         return $this->relationBuilder($relation[0])->buildField($relation[1]);
     }
     try {
         $mapping = $this->getMetadata()->getFieldMapping($name);
     } catch (MappingException $e) {
         throw new InvalidArgumentException($e->getMessage(), 0, $e);
     }
     $control = $this->controlFactory->create($this->getMetadata(), $mapping);
     $this->container->addComponent($control, $name);
     $this->mapper->load($this->entity, $control);
     return $control;
 }
Exemple #5
0
 protected function load(Form $form, $entity)
 {
     $this->entityFormMapper->load($entity, $form);
 }