/**
  * {@inheritdoc}
  */
 public function process(FormInterface $model, SymfonyFormInterface $form)
 {
     $result = new FormBuilderResult($model, $form);
     $data = $form->getData();
     foreach ($model->getFormElements() as $element) {
         $options = $element->getOptions();
         $config = $this->registry->getFormElementConfig($element);
         $label = isset($options['label']) ? $options['label'] : sprintf('Element %d', $element->getId());
         $value = $data[$config->getName()];
         $result->addPair($label, $value);
         // Let field modify result if needed
         $field = $this->registry->getFieldBuilder($element->getType());
         $field->processResult($result, $element, $value);
     }
     return $result;
 }
Esempio n. 2
0
 public function build(FormInterface $form, $data = null)
 {
     $options = ['label' => $form->getLegend(), 'method' => 'POST', 'action' => $this->router->generate($this->route, ['name' => $form->getName()])];
     // Dispatch event to tie in any options
     $event = new FormBuilderFactoryEvent($form, $options);
     $this->dispatcher->dispatch(Events::FORM_BUILD, $event);
     $builder = $this->factory->createNamedBuilder($form->getName(), 'form', $data, $event->getOptions());
     foreach ($form->getFormElements() as $element) {
         $fieldConfig = $this->registry->getFormElementConfig($element);
         // Fix options
         $options = $element->getOptions();
         unset($options['extra']);
         // Set constraints
         $options['constraints'] = $fieldConfig->getConstraints();
         // Add to form
         $builder->add($fieldConfig->getName(), $fieldConfig->getType(), $options);
     }
     return $builder->getForm();
 }