<?php
/**
* Pimcore Customer Management Framework Bundle
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (C) Elements.at New Media Solutions GmbH
* @license GPLv3
*/
namespace App\Form\FormConfigurator;
use Pimcore;
use Pimcore\Model\DataObject\Customer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Form;
use Pimcore\Model\Document\Tag\Area\Info;
use App\Document\Areabrick\AbstractAreabrick;
class RequestAQuoteNeuroFormType extends AbstractFormType
{
protected $formLabel = 'Request a Quote (Neuroscience)';
protected $emailDocumentPath = '/emails/neuroscience/request-a-quote';
protected $recaptcha = true;
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$translator = Pimcore::getContainer()->get('translator');
$customer = new Customer();
$prefixes = $customer->getClass()->getFieldDefinition('prefix');
$prefixOptions = [ $translator->trans('stoelting.forms.prefix.placeholder') => '' ];
foreach ($prefixes->getOptions() as $option) {
$prefixOptions[$option['key']] = $option['value'];
}
$builder
->add(
'Prefix',
ChoiceType::class,
[
'label' => $translator->trans('stoelting.forms.prefix'),
'placeholder' => $translator->trans('stoelting.forms.prefix.placeholder'),
'multiple' => false,
'choices' => $prefixOptions,
'choice_attr' => function ($key, $val, $index) {
return empty($key) ? ['disabled' => 'disabled'] : [];
}
]
)
->add('Firstname', TextType::class, [
'label' => $translator->trans('stoelting.forms.firstname'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.firstname.placeholder'),
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.firstname.required.message'),
])
]
])
->add('Lastname', TextType::class, [
'label' => $translator->trans('stoelting.forms.lastname'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.lastname.placeholder'),
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.lastname.required.message'),
])
]
])
->add('Institution', TextType::class, [
'label' => $translator->trans('stoelting.forms.institution'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.institution.placeholder'),
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.institution.required.message'),
])
]
])
->add('Address', TextType::class, [
'label' => $translator->trans('stoelting.forms.address'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.address.placeholder'),
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.address.required.message'),
])
]
])
->add('Country', TextType::class, [
'label' => $translator->trans('stoelting.forms.country'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.country.placeholder'),
'readonly' => false
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.country.required.message'),
])
]
])
->add('Email', EmailType::class, [
'label' => $translator->trans('stoelting.forms.email'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.email.placeholder'),
'readonly' => false
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.email.required.message'),
])
]
])
->add('Phone', TextType::class, [
'label' => $translator->trans('stoelting.forms.phone'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.phone.placeholder'),
'readonly' => false
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.phone.required.message'),
])
]
])
->add('ProductCategory', ChoiceType::class, [
'label' => $translator->trans('stoelting.forms.ProductCategory'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.ProductCategory.placeholder'),
'readonly' => false
],
'choices' => array_flip($this->getProductCategoryChoice($translator)),
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.ProductCategory.required.message'),
])
]
])
->add('ProductInformation', TextType::class, [
'label' => $translator->trans('stoelting.forms.ProductInformation'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.ProductInformation.placeholder'),
]
])
->add('Message', TextareaType::class, [
'label' => $translator->trans('stoelting.forms.message'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.message.placeholder'),
'readonly' => false,
'rows' => 5,
'max' => 500
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.message.required.message'),
])
]
])
->add('g-recaptcha-response', HiddenType::class, [
'attr' => [
'id' => 'g-recaptcha-response'
],
])
->add('action', HiddenType::class, [
'attr' => [
'id' => 'validate_captcha'
],
'data' => 'requestAQuoteNeuroForm'
])
->add('_submit', SubmitType::class, [
'label' => $translator->trans('stoelting.forms.send'),
'attr' => [
'class' => 'btn btn-primary request-quote-submit-element',
'onclick' => 'onSubmit()',
'data-gtm-event' => 'request-quote-click'
]
]);
}
/**
* @inheritDoc
*/
public function getBlockPrefix()
{
return '';
}
/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver)
{
}
protected function getProductCategoryChoice($translator)
{
return [
'stereotaxic' => $translator->trans('stoelting.forms.product-category.stereotaxic.choice'),
'behavior-any-maze' => $translator->trans('stoelting.forms.product-category.behavior-any-maze.choice'),
'other' => $translator->trans('stoelting.forms.product-category.other.choice')
];
}
/** @overide */
protected function formatEmailData(array $data)
{
$options = $this->getProductCategoryChoice(Pimcore::getContainer()->get('translator'));
$selectedOption = $data['ProductCategory'];
$data['ProductCategoryLabel'] = $options[$selectedOption] ?? $selectedOption;
return $data;
}
}