Exemplo n.º 1
0
 /**
  * @param WebForm $webForm
  *
  * @return \Symfony\Component\Form\Form
  */
 protected function getForm(WebForm $webForm)
 {
     $fb = $this->get('form.factory')->createNamedBuilder('web_form_' . $webForm->getName());
     $fb->setErrorBubbling(false);
     foreach ($webForm->getFields() as $field) {
         $fb->add($field->getName(), $field->getType(), ['required' => $field->getIsRequired()]);
     }
     if ($webForm->isIsUseCaptcha()) {
         $fb->add('captcha', 'genemu_captcha', ['mapped' => false]);
     }
     $fb->add('send', 'submit', ['attr' => ['class' => 'btn btn-success'], 'label' => $webForm->getSendButtonTitle()]);
     return $fb->getForm();
 }
 /**
  * @param \SmartCore\Module\WebForm\Entity\WebForm $webForm
  *
  * @return null|string
  *
  * @throws \Exception
  */
 protected function getNodePath(WebForm $webForm)
 {
     foreach ($this->get('cms.node')->findByModule('WebForm') as $node) {
         if ($node->getParam('webform_id') === (int) $webForm->getId()) {
             return $this->get('cms.folder')->getUri($node);
         }
     }
     return;
 }
 /**
  * @param WebForm $webForm
  *
  * @return \Symfony\Component\Form\Form
  */
 protected function getForm(WebForm $webForm)
 {
     $fb = $this->get('form.factory')->createNamedBuilder('web_form_' . $webForm->getName());
     $fb->setErrorBubbling(false);
     foreach ($webForm->getFields() as $field) {
         if (is_array($field->getParams())) {
             $options = $field->getParams();
         } else {
             $options = [];
         }
         $options['required'] = $field->getIsRequired();
         $options['label'] = $field->getTitle();
         if (isset($options['choices'])) {
             $options['choices'] = array_flip($options['choices']);
         }
         $type = $this->resolveTypeName($field->getType());
         $fb->add($field->getName(), $type, $options);
     }
     if ($webForm->isIsUseCaptcha()) {
         $fb->add('captcha', CaptchaType::class, ['mapped' => false]);
     }
     $fb->add('send', SubmitType::class, ['attr' => ['class' => 'btn btn-success'], 'label' => $webForm->getSendButtonTitle()]);
     return $fb->getForm();
 }