src/Form/FormConfigurator/ResearchPublishFormType.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore Customer Management Framework Bundle
  4.  * Full copyright and license information is available in
  5.  * LICENSE.md which is distributed with this source code.
  6.  *
  7.  * @copyright  Copyright (C) Elements.at New Media Solutions GmbH
  8.  * @license    GPLv3
  9.  */
  10. namespace App\Form\FormConfigurator;
  11. use Pimcore;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  18. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  19. use Symfony\Component\Form\FormBuilderInterface;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. use Symfony\Component\Validator\Constraint;
  22. use Symfony\Component\Validator\Constraints\NotBlank;
  23. use Pimcore\Model\DataObject\Customer;
  24. class ResearchPublishFormType extends AbstractFormType
  25. {
  26.     protected $formLabel 'Explore Publishing (Psychological)';
  27.     protected $emailDocumentPath '/emails/psychological-testing/research-publishing';
  28.     protected $recaptcha true;
  29.     /**
  30.      * @inheritDoc
  31.      */
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         $translator Pimcore::getContainer()->get('translator');
  35.         $customer = new Customer();
  36.         $prefixes $customer->getClass()->getFieldDefinition('prefix');
  37.         $prefixOptions = [ $translator->trans('stoelting.forms.prefix.placeholder') => '' ];
  38.         foreach ($prefixes->getOptions() as $option) {
  39.             $prefixOptions[$option['key']] = $option['value'];
  40.         }
  41.         $builder->add(
  42.                 'Prefix',
  43.                 ChoiceType::class,
  44.                 [
  45.                     'label'    => $translator->trans('stoelting.forms.prefix'),
  46.                     'placeholder' => $translator->trans('stoelting.forms.prefix.placeholder'),
  47.                     'multiple' => false,
  48.                     'choices'  => $prefixOptions,
  49.                     'choice_attr' => function ($key$val$index) {
  50.                         return empty($key) ? ['disabled' => 'disabled'] : [];
  51.                     }
  52.                 ]
  53.             )->add('Firstname'TextType::class, [
  54.                 'label' => $translator->trans('stoelting.forms.firstname'),
  55.                 'attr'        => [
  56.                     'placeholder' => $translator->trans('stoelting.forms.firstname.placeholder'),
  57.                 ],
  58.                 'constraints' => [
  59.                     new NotBlank([
  60.                         'message' => $translator->trans('stoelting.forms.firstname.required.message'),
  61.                     ])
  62.                 ]
  63.             ])
  64.             ->add('Lastname'TextType::class, [
  65.                 'label' => $translator->trans('stoelting.forms.lastname'),
  66.                 'attr'        => [
  67.                     'placeholder' => $translator->trans('stoelting.forms.lastname.placeholder'),
  68.                 ],
  69.                 'constraints' => [
  70.                     new NotBlank([
  71.                         'message' => $translator->trans('stoelting.forms.lastname.required.message'),
  72.                     ])
  73.                 ]
  74.             ])
  75.             ->add('Country'TextType::class, [
  76.                 'label' => $translator->trans('stoelting.forms.country'),
  77.                 'attr'        => [
  78.                     'placeholder' => $translator->trans('stoelting.forms.country.placeholder'),
  79.                     'readonly' => false
  80.                 ],
  81.                 'constraints' => [
  82.                     new NotBlank([
  83.                         'message' => $translator->trans('stoelting.forms.country.required.message'),
  84.                     ])
  85.                 ]
  86.             ])
  87.             ->add('Email'EmailType::class, [
  88.                 'label' => $translator->trans('stoelting.forms.email'),
  89.                 'attr'        => [
  90.                     'placeholder' => $translator->trans('stoelting.forms.email.placeholder'),
  91.                     'readonly' => false
  92.                 ],
  93.                 'constraints' => [
  94.                     new NotBlank([
  95.                         'message' => $translator->trans('stoelting.forms.email.required.message'),
  96.                     ])
  97.                 ]
  98.             ])
  99.             ->add('Phone'TextType::class, [
  100.                 'label' => $translator->trans('stoelting.forms.phone'),
  101.                 'attr'        => [
  102.                     'placeholder' => $translator->trans('stoelting.forms.phone.placeholder'),
  103.                     'readonly' => false
  104.                 ],
  105.                 'constraints' => [
  106.                     new NotBlank([
  107.                         'message' => $translator->trans('stoelting.forms.phone.required.message'),
  108.                     ])
  109.                 ]
  110.             ])
  111.             ->add('Description'TextareaType::class, [
  112.                 'label' => $translator->trans('stoelting.forms.Description'),
  113.                 'attr'        => [
  114.                     'placeholder' => $translator->trans('stoelting.forms.Description.placeholder'),
  115.                     'readonly' => false,
  116.                     'rows' => 5,
  117.                     'max' => 500
  118.                 ],
  119.                 'constraints' => [
  120.                     new NotBlank([
  121.                         'message' => $translator->trans('stoelting.forms.Description.required.message'),
  122.                     ])
  123.                 ]
  124.             ])
  125.             ->add('Message'TextareaType::class, [
  126.                 'label' => $translator->trans('stoelting.forms.research.message'),
  127.                 'attr'        => [
  128.                     'placeholder' => $translator->trans('stoelting.forms.research.message.placeholder'),
  129.                     'readonly' => false,
  130.                     'rows' => 5,
  131.                     'max' => 500
  132.                 ]
  133.             ])
  134.             ->add('g-recaptcha-response'HiddenType::class, [
  135.                 'attr' => [
  136.                     'id' => 'g-recaptcha-response'
  137.                 ],
  138.             ])
  139.             ->add('action'HiddenType::class, [
  140.                 'attr' => [
  141.                     'id' => 'validate_captcha'
  142.                 ],
  143.                 'data' => 'requestAQuoteNeuroForm'
  144.             ])
  145.             ->add('_submit'SubmitType::class, [
  146.                 'label' => $translator->trans('stoelting.forms.send'),
  147.                 'attr' => [
  148.                     'class' => 'btn btn-primary',
  149.                     'onclick' => 'onSubmit()'
  150.                 ]
  151.             ]);
  152.     }
  153.     /**
  154.      * @inheritDoc
  155.      */
  156.     public function getBlockPrefix()
  157.     {
  158.         return '';
  159.     }
  160.     /**
  161.      * @inheritDoc
  162.      */
  163.     public function configureOptions(OptionsResolver $resolver)
  164.     {
  165.     }
  166. }