src/Form/EmployeeHistoryType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\EmployeeDepartment;
  4. use App\Entity\EmployeeHistory;
  5. use App\Entity\EmployeePosition;
  6. use App\Enum\EmployeeHistory\SalaryType;
  7. use App\Form\DataTransformer\FrenchToDateTimeTransformer;
  8. use App\Repository\EmployeeHistoryRepository;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\Extension\Core\Type\EnumType;
  11. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. class EmployeeHistoryType extends Form
  16. {
  17.     /** @var EmployeeHistoryRepository */
  18.     protected $employeeHistoryRepository;
  19.     /** @var FrenchToDateTimeTransformer */
  20.     protected $transformer;
  21.     /**
  22.      * UserType constructor.
  23.      * @param EmployeeHistoryRepository $employeeHistoryRepository
  24.      */
  25.     public function __construct(
  26.         EmployeeHistoryRepository   $employeeHistoryRepository,
  27.         FrenchToDateTimeTransformer $transformer
  28.     )
  29.     {
  30.         $this->employeeHistoryRepository $employeeHistoryRepository;
  31.         $this->transformer $transformer;
  32.     }
  33.     public function buildForm(FormBuilderInterface $builder, array $options)
  34.     {
  35.         $builder
  36.             ->add(
  37.                 'department',
  38.                 EntityType::class,
  39.                 [
  40.                     'class' => EmployeeDepartment::class,
  41.                     'choice_label' => 'name',
  42.                     'multiple' => false,
  43.                     'label' => 'Département',
  44.                     'required' => true,
  45.                     'disabled' => $options['disabled'],
  46.                     'attr' => array_merge(
  47.                         $this->selectAttr,
  48.                         [
  49.                             'placeholder' => 'Département',
  50.                         ]
  51.                     ),
  52.                 ]
  53.             )
  54.             ->add(
  55.                 'position',
  56.                 EntityType::class,
  57.                 [
  58.                     'class' => EmployeePosition::class,
  59.                     'choice_label' => 'name',
  60.                     'multiple' => false,
  61.                     'label' => 'Poste',
  62.                     'required' => true,
  63.                     'disabled' => $options['disabled'],
  64.                     'attr' => array_merge(
  65.                         $this->selectAttr,
  66.                         [
  67.                             'placeholder' => 'Poste',
  68.                         ]
  69.                     ),
  70.                 ]
  71.             )
  72.             ->add(
  73.                 'startDate',
  74.                 TextType::class,
  75.                 [
  76.                     'label' => 'Date de début',
  77.                     'required' => false,
  78.                     'attr' => array_merge(
  79.                         $this->dateAttr,
  80.                         [
  81.                             'class' => 'form-control form-control-solid eh_date',
  82.                             'placeholder' => 'Date de début',
  83.                         ]
  84.                     ),
  85.                     'disabled' => $options['disabled']
  86.                 ]
  87.             )
  88.             ->add(
  89.                 'endDate',
  90.                 TextType::class,
  91.                 [
  92.                     'label' => 'Date de fin',
  93.                     'required' => false,
  94.                     'attr' => array_merge(
  95.                         $this->dateAttr,
  96.                         [
  97.                             'class' => 'form-control form-control-solid eh_date',
  98.                             'placeholder' => 'Date de fin',
  99.                         ]
  100.                     ),
  101.                     'disabled' => $options['disabled']
  102.                 ]
  103.             )
  104.             ->add(
  105.                 'reason',
  106.                 TextType::class,
  107.                 [
  108.                     'label' => 'Commentaire',
  109.                     'required' => false,
  110.                     'attr' => array_merge(
  111.                         $this->inputAttr,
  112.                         [
  113.                             'placeholder' => 'Commentaire',
  114.                         ]
  115.                     ),
  116.                     'disabled' => $options['disabled']
  117.                 ]
  118.             )
  119.             ->add(
  120.                 'salaryType',
  121.                 EnumType::class,
  122.                 [
  123.                     'class' => SalaryType::class,
  124.                     'choice_label' => function (SalaryType $salaryType) {
  125.                         return $salaryType->title();
  126.                     },
  127.                     'label' => 'Type de salaire',
  128.                     'disabled' => $options['disabled'],
  129.                     'attr' => array_merge(
  130.                         $this->selectAttr,
  131.                         [
  132.                         ]
  133.                     ),
  134.                 ]
  135.             )
  136.             ->add(
  137.                 'price',
  138.                 NumberType::class,
  139.                 [
  140.                     'label' => 'Tarif',
  141.                     'required' => true,
  142.                     'html5' => true,
  143.                     'attr' => array_merge(
  144.                         $this->inputAttr,
  145.                         [
  146.                             'placeholder' => 'Tarif',
  147.                         ]
  148.                     ),
  149.                     'disabled' => $options['disabled']
  150.                 ]
  151.             );
  152.         $builder->get('startDate')->addModelTransformer($this->transformer);
  153.         $builder->get('endDate')->addModelTransformer($this->transformer);
  154.     }
  155.     public function configureOptions(OptionsResolver $resolver)
  156.     {
  157.         $resolver->setDefaults(
  158.             [
  159.                 'data_class' => EmployeeHistory::class,
  160.                 'disabled' => false
  161.             ]
  162.         );
  163.     }
  164. }