src/Form/VehicleInspectionExpType.php line 12

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Vehicles;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\DateType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Form\CallbackTransformer;
  9. class VehicleInspectionExpType extends AbstractType
  10. {
  11.     /**
  12.      * {@inheritdoc}
  13.      */
  14.     public function buildForm(FormBuilderInterface $builder, array $options)
  15.     {
  16.         $builder->add(
  17.             $builder->create(
  18.                 'inspectionExpirationDate'DateType::class, array(
  19.                 'label'    => 'expire date',
  20.                 'widget'   => 'single_text',
  21.                 'format'   => 'yyyy-MM-dd',
  22.                 'html5'    => false,
  23.                 'required' => false 
  24.             ))
  25.                 ->addModelTransformer(new CallbackTransformer(
  26.                         function ($inspectionExpirationDate) {
  27.                             // manually set locale to English as PHP intl changes date format to the current locale which causes the date to be shown with Arabic digits in Arabic interface
  28.                             \Locale::setDefault('en');
  29.                             return $inspectionExpirationDate;
  30.                         },
  31.                         function ($inspectionExpirationDate) {
  32.                             return $inspectionExpirationDate;
  33.                         }
  34.                     ))
  35.         );
  36.     }
  37.     
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function configureOptions(OptionsResolver $resolver)
  42.     {
  43.         $resolver->setDefaults(array(
  44.             'data_class'         => Vehicles::class,
  45.             'translation_domain' => 'vehicles'
  46.         ));
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function getBlockPrefix()
  52.     {
  53.         return 'appbundle_vehicles';
  54.     }
  55. }