<?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\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Count;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Form;
use Pimcore\Model\Document\Tag\Area\Info;
use App\Document\Areabrick\AbstractAreabrick;
use Symfony\Component\Validator\Constraints\Regex;
class ContactUsExtendedFormType extends AbstractFormType
{
protected $formLabel = 'Contact Us (Neuroscience/AnyMaze)';
protected $emailDocumentPath = '/emails/neuroscience/contact-us';
protected $recaptcha = true;
protected function formatEmailData(array $data)
{
foreach ($data as $key => $item) {
if (is_array($item) && ($key == 'Prefference')) {
$data[$key] = ucwords(implode(", ", $item));
}
}
if ($data['Division'] != 'neuroscience') {
$this->emailDocumentPath = '/emails/'.lcfirst($data['Division']).'/contact-us';
}
return $data;
}
/**
* @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('Division', ChoiceType::class, [
'label' => $translator->trans('stoelting.forms.division'),
'choices' => [
'Neuroscience' => 'neuroscience',
'ANY-maze' => 'any-maze',
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.division.required.message'),
])
]
])
->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('Company', TextType::class, [
'label' => $translator->trans('stoelting.forms.institution_company'),
'attr' => [
'placeholder' => $translator->trans('stoelting.forms.institution_company.placeholder'),
'readonly' => false
]
])
/*->add('Country', CountryType::class, [
'label' => $translator->trans('stoelting.forms.country'),
'data' => 'US',
'attr' => [
'class' => 'country-select',
'placeholder' => $translator->trans('stoelting.forms.country.placeholder'),
'onchange' => 'javascript:$("#CountryName").val($(this).find("option:selected").text())',
'readonly' => false
],
'constraints' => [
new NotBlank([
'message' => $translator->trans('stoelting.forms.country.required.message'),
])
]
])
->add('CountryName', HiddenType::class, [
'label' => false,
'data' => 'United States',
'attr' => [
'class' => 'js-get-selected-label',
'data-target' => 'country-select'
]
])*/
->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'),
]),
new Regex(
[
'pattern' => '/[^@]+@[^\.]+\..+/',
'message' => $translator->trans('stoelting.invalid-email-check'),
]
)
]
])
->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('Prefference', ChoiceType::class, [
'label' => $translator->trans('stoelting.forms.preffered_contact_method'),
'choices' => [
'Email' => 'email',
'Phone' => 'telephone'
],
'multiple' => true,
'expanded' => true,
'choice_label' => function ($choice, $key, $value) use ($translator){
return $translator->trans('stoelting.forms.prefference_'.$value);
},
'constraints' => [
new Count([
'min' => 1,
'minMessage' => $translator->trans('stoelting.forms.preffered_contact_method.required.message'),
])
]
])
->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' => 'neuroscienceContactForm'
])
->add('_submit', ButtonType::class, [
'label' => $translator->trans('stoelting.forms.send'),
'attr' => [
'class' => 'btn btn-primary',
'onclick' => 'onSubmit()'
]
]);
}
/**
* @inheritDoc
*/
public function getBlockPrefix()
{
return '';
}
/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver)
{
}
protected function getDocumentPath(array $params)
{
if ($params['Division'] != 'neuroscience') {
return str_replace('/neuroscience/', '/'.$params['Division'].'/', $this->emailDocumentPath);
}
return $this->emailDocumentPath;
}
}