src/Form/FormConfigurator/RequestAQuoteNeuroFormType.php line 62

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 Pimcore\Model\DataObject\Customer;
  13. use Symfony\Component\Form\AbstractType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  20. use Symfony\Component\Form\FormBuilderInterface;
  21. use Symfony\Component\OptionsResolver\OptionsResolver;
  22. use Symfony\Component\Validator\Constraints\NotBlank;
  23. use Symfony\Component\Form\Form;
  24. use Pimcore\Model\Document\Tag\Area\Info;
  25. use App\Document\Areabrick\AbstractAreabrick;
  26. class RequestAQuoteNeuroFormType extends AbstractFormType
  27. {
  28.     protected $formLabel 'Request a Quote (Neuroscience)';
  29.     protected $emailDocumentPath '/emails/neuroscience/request-a-quote';
  30.     protected $recaptcha true;
  31.     /**
  32.      * @inheritDoc
  33.      */
  34.     public function buildForm(FormBuilderInterface $builder, array $options)
  35.     {
  36.         $translator Pimcore::getContainer()->get('translator');
  37.         $customer = new Customer();
  38.         $prefixes $customer->getClass()->getFieldDefinition('prefix');
  39.         $prefixOptions = [ $translator->trans('stoelting.forms.prefix.placeholder') => '' ];
  40.         foreach ($prefixes->getOptions() as $option) {
  41.             $prefixOptions[$option['key']] = $option['value'];
  42.         }
  43.         $builder
  44.             ->add(
  45.                 'Prefix',
  46.                 ChoiceType::class,
  47.                 [
  48.                     'label'    => $translator->trans('stoelting.forms.prefix'),
  49.                     'placeholder' => $translator->trans('stoelting.forms.prefix.placeholder'),
  50.                     'multiple' => false,
  51.                     'choices'  => $prefixOptions,
  52.                     'choice_attr' => function ($key$val$index) {
  53.                         return empty($key) ? ['disabled' => 'disabled'] : [];
  54.                     }
  55.                 ]
  56.             )
  57.             ->add('Firstname'TextType::class, [
  58.                 'label' => $translator->trans('stoelting.forms.firstname'),
  59.                 'attr'        => [
  60.                     'placeholder' => $translator->trans('stoelting.forms.firstname.placeholder'),
  61.                 ],
  62.                 'constraints' => [
  63.                     new NotBlank([
  64.                         'message' => $translator->trans('stoelting.forms.firstname.required.message'),
  65.                     ])
  66.                 ]
  67.             ])
  68.             ->add('Lastname'TextType::class, [
  69.                 'label' => $translator->trans('stoelting.forms.lastname'),
  70.                 'attr'        => [
  71.                     'placeholder' => $translator->trans('stoelting.forms.lastname.placeholder'),
  72.                 ],
  73.                 'constraints' => [
  74.                     new NotBlank([
  75.                         'message' => $translator->trans('stoelting.forms.lastname.required.message'),
  76.                     ])
  77.                 ]
  78.             ])
  79.             ->add('Institution'TextType::class, [
  80.                 'label' => $translator->trans('stoelting.forms.institution'),
  81.                 'attr'        => [
  82.                     'placeholder' => $translator->trans('stoelting.forms.institution.placeholder'),
  83.                 ],
  84.                 'constraints' => [
  85.                     new NotBlank([
  86.                         'message' => $translator->trans('stoelting.forms.institution.required.message'),
  87.                     ])
  88.                 ]
  89.             ])
  90.             ->add('Address'TextType::class, [
  91.                 'label' => $translator->trans('stoelting.forms.address'),
  92.                 'attr'        => [
  93.                     'placeholder' => $translator->trans('stoelting.forms.address.placeholder'),
  94.                 ],
  95.                 'constraints' => [
  96.                     new NotBlank([
  97.                         'message' => $translator->trans('stoelting.forms.address.required.message'),
  98.                     ])
  99.                 ]
  100.             ])
  101.             ->add('Country'TextType::class, [
  102.                 'label' => $translator->trans('stoelting.forms.country'),
  103.                 'attr'        => [
  104.                     'placeholder' => $translator->trans('stoelting.forms.country.placeholder'),
  105.                     'readonly' => false
  106.                 ],
  107.                 'constraints' => [
  108.                     new NotBlank([
  109.                         'message' => $translator->trans('stoelting.forms.country.required.message'),
  110.                     ])
  111.                 ]
  112.             ])
  113.             ->add('Email'EmailType::class, [
  114.                 'label' => $translator->trans('stoelting.forms.email'),
  115.                 'attr'        => [
  116.                     'placeholder' => $translator->trans('stoelting.forms.email.placeholder'),
  117.                     'readonly' => false
  118.                 ],
  119.                 'constraints' => [
  120.                     new NotBlank([
  121.                         'message' => $translator->trans('stoelting.forms.email.required.message'),
  122.                     ])
  123.                 ]
  124.             ])
  125.             ->add('Phone'TextType::class, [
  126.                 'label' => $translator->trans('stoelting.forms.phone'),
  127.                 'attr'        => [
  128.                     'placeholder' => $translator->trans('stoelting.forms.phone.placeholder'),
  129.                     'readonly' => false
  130.                 ],
  131.                 'constraints' => [
  132.                     new NotBlank([
  133.                         'message' => $translator->trans('stoelting.forms.phone.required.message'),
  134.                     ])
  135.                 ]
  136.             ])
  137.             ->add('ProductCategory'ChoiceType::class, [
  138.                 'label' => $translator->trans('stoelting.forms.ProductCategory'),
  139.                 'attr'        => [
  140.                     'placeholder' => $translator->trans('stoelting.forms.ProductCategory.placeholder'),
  141.                     'readonly' => false
  142.                 ],
  143.                 'choices'  => array_flip($this->getProductCategoryChoice($translator)),
  144.                 'constraints' => [
  145.                     new NotBlank([
  146.                         'message' => $translator->trans('stoelting.forms.ProductCategory.required.message'),
  147.                     ])
  148.                 ]
  149.             ])
  150.             ->add('ProductInformation'TextType::class, [
  151.                 'label' => $translator->trans('stoelting.forms.ProductInformation'),
  152.                 'attr'        => [
  153.                     'placeholder' => $translator->trans('stoelting.forms.ProductInformation.placeholder'),
  154.                 ]
  155.             ])
  156.             ->add('Message'TextareaType::class, [
  157.                 'label' => $translator->trans('stoelting.forms.message'),
  158.                 'attr'        => [
  159.                     'placeholder' => $translator->trans('stoelting.forms.message.placeholder'),
  160.                     'readonly' => false,
  161.                     'rows' => 5,
  162.                     'max' => 500
  163.                 ],
  164.                 'constraints' => [
  165.                     new NotBlank([
  166.                         'message' => $translator->trans('stoelting.forms.message.required.message'),
  167.                     ])
  168.                 ]
  169.             ])
  170.             ->add('g-recaptcha-response'HiddenType::class, [
  171.                 'attr' => [
  172.                     'id' => 'g-recaptcha-response'
  173.                 ],
  174.             ])
  175.             ->add('action'HiddenType::class, [
  176.                 'attr' => [
  177.                     'id' => 'validate_captcha'
  178.                 ],
  179.                 'data' => 'requestAQuoteNeuroForm'
  180.             ])
  181.             ->add('_submit'SubmitType::class, [
  182.                 'label' => $translator->trans('stoelting.forms.send'),
  183.                 'attr' => [
  184.                     'class' => 'btn btn-primary request-quote-submit-element',
  185.                     'onclick' => 'onSubmit()',
  186.                     'data-gtm-event' => 'request-quote-click'
  187.                 ]
  188.             ]);
  189.     }
  190.     /**
  191.      * @inheritDoc
  192.      */
  193.     public function getBlockPrefix()
  194.     {
  195.         return '';
  196.     }
  197.     /**
  198.      * @inheritDoc
  199.      */
  200.     public function configureOptions(OptionsResolver $resolver)
  201.     {
  202.     }
  203.     protected function getProductCategoryChoice($translator)
  204.     {
  205.         return [
  206.             'stereotaxic' => $translator->trans('stoelting.forms.product-category.stereotaxic.choice'),
  207.             'behavior-any-maze' => $translator->trans('stoelting.forms.product-category.behavior-any-maze.choice'),
  208.             'other' => $translator->trans('stoelting.forms.product-category.other.choice')
  209.         ];
  210.     }
  211.     /** @overide */
  212.     protected function formatEmailData(array $data)
  213.     {
  214.         $options $this->getProductCategoryChoice(Pimcore::getContainer()->get('translator'));
  215.         $selectedOption $data['ProductCategory'];
  216.         $data['ProductCategoryLabel'] = $options[$selectedOption] ?? $selectedOption;
  217.         return $data;
  218.     }
  219. }