src/Form/EmployeeType.php line 142

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Employee;
  4. use App\Enum\Employee\Gender;
  5. use App\Enum\Employee\RelationShipStatus;
  6. use App\Form\DataTransformer\FrenchDateToDateTimeTransformer;
  7. use App\Repository\EmployeeRepository;
  8. use Symfony\Component\Form\Extension\Core\Type\EnumType;
  9. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  10. use Symfony\Component\Form\Extension\Core\Type\TelType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. class EmployeeType extends Form
  15. {
  16.     /** @var EmployeeRepository */
  17.     protected $employeeRepository;
  18.     /** @var FrenchDateToDateTimeTransformer */
  19.     protected $transformer;
  20.     /**
  21.      * UserType constructor.
  22.      * @param EmployeeRepository $employeeRepository
  23.      */
  24.     public function __construct(
  25.         EmployeeRepository              $employeeRepository,
  26.         FrenchDateToDateTimeTransformer $transformer
  27.     )
  28.     {
  29.         $this->employeeRepository $employeeRepository;
  30.         $this->transformer $transformer;
  31.     }
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         $builder
  35.             ->add(
  36.                 'gender',
  37.                 EnumType::class,
  38.                 [
  39.                     'class' => Gender::class,
  40.                     'choice_label' => function (Gender $gender) {
  41.                         return $gender->title();
  42.                     },
  43.                     'label' => 'Civilité',
  44.                     'disabled' => $options['disabled'],
  45.                     'attr' => array_merge(
  46.                         $this->selectAttr,
  47.                         [
  48.                         ]
  49.                     ),
  50.                 ]
  51.             )
  52.             ->add(
  53.                 'firstName',
  54.                 TextType::class,
  55.                 [
  56.                     'label' => 'Prénom',
  57.                     'required' => true,
  58.                     'attr' => array_merge(
  59.                         $this->inputAttr,
  60.                         [
  61.                             'placeholder' => 'Prénom',
  62. //                            'attr' => [
  63. //                                'readonly' => true
  64. //                            ]
  65.                         ]
  66.                     ),
  67.                     'disabled' => $options['disabled']
  68.                 ]
  69.             )
  70.             ->add(
  71.                 'lastName',
  72.                 TextType::class,
  73.                 [
  74.                     'label' => 'Nom',
  75.                     'required' => true,
  76.                     'attr' => array_merge(
  77.                         $this->inputAttr,
  78.                         [
  79.                             'placeholder' => 'Nom',
  80.                         ]
  81.                     ),
  82.                     'disabled' => $options['disabled']
  83.                 ],
  84.             )
  85.             ->add(
  86.                 'phoneNumber',
  87.                 TelType::class,
  88.                 [
  89.                     'label' => 'Téléphone',
  90.                     'required' => true,
  91.                     'attr' => array_merge(
  92.                         $this->inputAttr,
  93.                         [
  94.                             'placeholder' => 'Téléphone',
  95.                         ]
  96.                     ),
  97.                     'disabled' => $options['disabled']
  98.                 ]
  99.             )
  100.             ->add(
  101.                 'cin',
  102.                 TextType::class,
  103.                 [
  104.                     'label' => 'N° CIN',
  105.                     'required' => false,
  106.                     'attr' => array_merge(
  107.                         $this->inputAttr,
  108.                         [
  109.                             'placeholder' => 'N° CIN',
  110.                         ]
  111.                     ),
  112.                     'disabled' => $options['disabled']
  113.                 ]
  114.             )
  115.             ->add(
  116.                 'dateOfBirth',
  117.                 TextType::class,
  118.                 [
  119.                     'label' => 'Date de naissance',
  120.                     'required' => false,
  121.                     'attr' => array_merge(
  122.                         $this->dateAttr,
  123.                         [
  124.                             'placeholder' => 'Date de naissance',
  125.                         ]
  126.                     ),
  127.                     'disabled' => $options['disabled']
  128.                 ]
  129.             )
  130.             ->add(
  131.                 'relationshipStatus',
  132.                 EnumType::class,
  133.                 [
  134.                     'class' => RelationShipStatus::class,
  135.                     'choice_label' => function (RelationShipStatus $gender) {
  136.                         return $gender->title();
  137.                     },
  138.                     'label' => 'Situation amoureuse',
  139.                     'disabled' => $options['disabled'],
  140.                     'attr' => array_merge(
  141.                         $this->selectAttr,
  142.                         [
  143.                         ]
  144.                     ),
  145.                 ]
  146.             )
  147.             ->add(
  148.                 'numberOfChildrens',
  149.                 IntegerType::class,
  150.                 [
  151.                     'label' => 'Nombre d\'enfant',
  152.                     'required' => true,
  153.                     'attr' => array_merge(
  154.                         $this->selectAttr,
  155.                         [
  156.                             'placeholder' => 'Nombre d\'enfant',
  157.                         ]
  158.                     ),
  159.                     'disabled' => $options['disabled']
  160.                 ]
  161.             )
  162. //            ->add(
  163. //                'address',
  164. //                TextType::class,
  165. //                [
  166. //                    'label' => 'Adresse',
  167. //                    'required' => false,
  168. //                    'attr' => array_merge(
  169. //                        $this->inputAttr,
  170. //                        [
  171. //                            'placeholder' => 'Adresse',
  172. //                        ]
  173. //                    ),
  174. //                ]
  175. //            )
  176.             ->add(
  177.                 'dateOld',
  178.                 TextType::class,
  179.                 [
  180.                     'label' => 'Date d\'ancienneté',
  181.                     'required' => false,
  182.                     'attr' => array_merge(
  183.                         $this->dateAttr,
  184.                         [
  185.                             'placeholder' => 'Date d\'ancienneté',
  186.                         ]
  187.                     ),
  188.                     'disabled' => $options['disabled']
  189.                 ]
  190.             )
  191.             ->add(
  192.                 'registrationNumber',
  193.                 IntegerType::class,
  194.                 [
  195.                     'label' => 'Matricule',
  196.                     'required' => false,
  197.                     'attr' => array_merge(
  198.                         $this->inputAttr,
  199.                         [
  200.                             'placeholder' => 'Matricule',
  201. //                            'attr' => [
  202. //                                'readonly' => true
  203. //                            ]
  204.                         ]
  205.                     ),
  206.                     'disabled' => $options['disabled']
  207.                 ]
  208.             )
  209.             ->add(
  210.                 'cnss',
  211.                 TextType::class,
  212.                 [
  213.                     'label' => 'N° CNSS',
  214.                     'required' => false,
  215.                     'attr' => array_merge(
  216.                         $this->inputAttr,
  217.                         [
  218.                             'placeholder' => 'N° CNSS',
  219.                         ]
  220.                     ),
  221.                     'disabled' => $options['disabled']
  222.                 ]
  223.             )
  224.             ->add(
  225.                 'dateCnss',
  226.                 TextType::class,
  227.                 [
  228.                     'label' => 'Date de déclaration CNSS',
  229.                     'required' => false,
  230.                     'attr' => array_merge(
  231.                         $this->dateAttr,
  232.                         [
  233.                             'placeholder' => 'Date de déclaration CNSS',
  234.                         ]
  235.                     ),
  236.                     'disabled' => $options['disabled']
  237.                 ]
  238.             );
  239.         $builder->get('dateOfBirth')->addModelTransformer($this->transformer);
  240.         $builder->get('dateOld')->addModelTransformer($this->transformer);
  241.         $builder->get('dateCnss')->addModelTransformer($this->transformer);
  242.     }
  243.     public function configureOptions(OptionsResolver $resolver)
  244.     {
  245.         $resolver->setDefaults(
  246.             [
  247.                 'data_class' => Employee::class,
  248.                 'disabled' => false
  249.             ]
  250.         );
  251.     }
  252. }