<?php
namespace App\Form\Backend\Shared;
use App\Entity\Person;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PersonType extends AbstractType
{
public const FIELD_SALUTATION = 'salutation';
/**
* @param FormBuilderInterface $builder
* @param array $options
*
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('firstname')
->add('lastname');
$this->addSalutationField($builder);
}
/**
* @param FormBuilderInterface $builder
*
* @return void
*/
protected function addSalutationField(FormBuilderInterface $builder): void
{
$builder->add(static::FIELD_SALUTATION, ChoiceType::class, [
'choices' => [
'app.person.salutation.salutation_mr' => 'salutation_mr',
'app.person.salutation.salutation_ms' => 'salutation_ms',
'app.person.salutation.salutation_d' => 'salutation_d',
]
]);
}
/**
* @param OptionsResolver $resolver
*
* @return void
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Person::class,
]);
}
}