<?php
namespace App\Form;
use App\Entity\EmployeeDepartment;
use App\Entity\EmployeeHistory;
use App\Entity\EmployeePosition;
use App\Enum\EmployeeHistory\SalaryType;
use App\Form\DataTransformer\FrenchToDateTimeTransformer;
use App\Repository\EmployeeHistoryRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EmployeeHistoryType extends Form
{
/** @var EmployeeHistoryRepository */
protected $employeeHistoryRepository;
/** @var FrenchToDateTimeTransformer */
protected $transformer;
/**
* UserType constructor.
* @param EmployeeHistoryRepository $employeeHistoryRepository
*/
public function __construct(
EmployeeHistoryRepository $employeeHistoryRepository,
FrenchToDateTimeTransformer $transformer
)
{
$this->employeeHistoryRepository = $employeeHistoryRepository;
$this->transformer = $transformer;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'department',
EntityType::class,
[
'class' => EmployeeDepartment::class,
'choice_label' => 'name',
'multiple' => false,
'label' => 'Département',
'required' => true,
'disabled' => $options['disabled'],
'attr' => array_merge(
$this->selectAttr,
[
'placeholder' => 'Département',
]
),
]
)
->add(
'position',
EntityType::class,
[
'class' => EmployeePosition::class,
'choice_label' => 'name',
'multiple' => false,
'label' => 'Poste',
'required' => true,
'disabled' => $options['disabled'],
'attr' => array_merge(
$this->selectAttr,
[
'placeholder' => 'Poste',
]
),
]
)
->add(
'startDate',
TextType::class,
[
'label' => 'Date de début',
'required' => false,
'attr' => array_merge(
$this->dateAttr,
[
'class' => 'form-control form-control-solid eh_date',
'placeholder' => 'Date de début',
]
),
'disabled' => $options['disabled']
]
)
->add(
'endDate',
TextType::class,
[
'label' => 'Date de fin',
'required' => false,
'attr' => array_merge(
$this->dateAttr,
[
'class' => 'form-control form-control-solid eh_date',
'placeholder' => 'Date de fin',
]
),
'disabled' => $options['disabled']
]
)
->add(
'reason',
TextType::class,
[
'label' => 'Commentaire',
'required' => false,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Commentaire',
]
),
'disabled' => $options['disabled']
]
)
->add(
'salaryType',
EnumType::class,
[
'class' => SalaryType::class,
'choice_label' => function (SalaryType $salaryType) {
return $salaryType->title();
},
'label' => 'Type de salaire',
'disabled' => $options['disabled'],
'attr' => array_merge(
$this->selectAttr,
[
]
),
]
)
->add(
'price',
NumberType::class,
[
'label' => 'Tarif',
'required' => true,
'html5' => true,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Tarif',
]
),
'disabled' => $options['disabled']
]
);
$builder->get('startDate')->addModelTransformer($this->transformer);
$builder->get('endDate')->addModelTransformer($this->transformer);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => EmployeeHistory::class,
'disabled' => false
]
);
}
}