<?php
namespace App\Form;
use App\Entity\Package;
use App\Entity\Participant;
use Shapecode\Bundle\HiddenEntityTypeBundle\Form\Type\HiddenEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Translation\TranslatorInterface;
class AddParticipantType extends AbstractType
{
/**
* @var Translator
*/
private $translator;
/**
* @var UrlGeneratorInterface
*/
private UrlGeneratorInterface $router;
/**
* @param TranslatorInterface $translator
* @param UrlGeneratorInterface $router
*/
public function __construct(
TranslatorInterface $translator,
UrlGeneratorInterface $router
)
{
$this->translator = $translator;
$this->router = $router;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'id',
HiddenType::class
)
->add(
'gdpr',
ChoiceType::class,
[
'label' => 'Politica de confidentialitate',
'help' => $this->translator->trans('general.gdpr.text'),
'help_html' => true,
'help_translation_parameters' => [
'%privacy_policy%' => '<a target="_blank" href="'
. $this->router->generate('app_gdpr') . '">'
. $this->translator->trans('general.gdpr.privacy_policy') . '</a>'
],
'placeholder' => $this->translator->trans('general.placeholder'),
'choices' => [
'general.accept' => true
],
'required' => true,
'mapped' => false
]
)
->add(
'name',
TextType::class,
[
'label' => $this->translator->trans('participant.label.name'),
'required' => true,
'help' => $this->translator->trans('participant.help.name').' '.$this->translator->trans('general.mandatory'),
]
)
->add(
'company',
TextType::class,
[
'label' => $this->translator->trans('participant.label.company'),
'required' => true,
'help' => $this->translator->trans('participant.help.company').' '.$this->translator->trans('general.mandatory'),
]
)
->add(
'vatId',
TextType::class,
[
'label' => $this->translator->trans('participant.label.vatId'),
'required' => true,
'help' => $this->translator->trans('participant.help.vatId').' '.$this->translator->trans('general.mandatory')
]
)
->add(
'email',
EmailType::class,
[
'label' => $this->translator->trans('participant.label.email'),
'required' => false,
'help' => $this->translator->trans('participant.help.email'),
]
)
->add(
'phone',
TextType::class,
[
'label' => $this->translator->trans('participant.label.phone'),
'required' => false,
'help' => $this->translator->trans('participant.help.phone'),
]
);
if (!$options['isExposed']) {
$builder->add(
'status',
ChoiceType::class,
[
'label' => 'Status badge',
'choices' => [
$this->translator->trans('participant.badgeStatus.unprinted') => Participant::STATUS_ENABLED_NOT_PRINTED,
$this->translator->trans('participant.badgeStatus.printed') => Participant::STATUS_ENABLED_PRINTED,
],
'help' => $this->translator->trans('participant.help.badge'),
]
)
->add('package',
EntityType::class,
[
'label' => $this->translator->trans('participant.table.package'),
'class' => Package::class,
'data' => $options['defaultPackage'],
'required' => true,
'help' => $this->translator->trans('participant.help.package').' '.$this->translator->trans('general.mandatory'),
],
);
} else {
$builder->add('package',
HiddenEntityType::class,
[
'label' => $this->translator->trans('participant.table.package'),
'class' => Package::class,
'data' => $options['defaultPackage'],
'required' => true,
'help' => $this->translator->trans('participant.help.package').' '.$this->translator->trans('general.mandatory'),
],
);
}
$builder
->add(
'save',
SubmitType::class,
[
'label' => $this->translator->trans('general.save'),
]
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => Participant::class,
'defaultPackage' => null,
'isExposed' => false
]
);
$resolver->setAllowedTypes('defaultPackage', Package::class);
}
}