src/Form/UserRegistrationIdentityInfoType.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\UserIdentityInfo;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\FileType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\Regex;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. class UserRegistrationIdentityInfoType extends AbstractType
  12. {
  13.     /**
  14.      * @var Translator
  15.      */
  16.     protected $translator;
  17.     /**
  18.      * AuctionVehiclesBiddingType constructor.
  19.      * @param Translator|null $translator
  20.      */
  21.     public function __construct(TranslatorInterface $translatornull)
  22.     {
  23.         $this->translator $translator;
  24.     }
  25.     /**
  26.      * @param FormBuilderInterface $builder
  27.      * @param array $options
  28.      */
  29.     public function buildForm(FormBuilderInterface $builder, array $options)
  30.     {
  31.         $trans $this->translator;
  32.         $nameValidation  $trans->trans('you should add the first name', [], 'validators');
  33.         $idNumValidation $trans->trans('you should add correct identification number', [], 'validators');
  34.         $required_field  $trans->trans('required field', [], 'vehicles');
  35.         $builder->add('firstnameAr'     ,null, array(
  36.             'label'    => 'first name',
  37.             'required' => true,
  38.             'attr'     => [
  39.                 'validate-msg' => $nameValidation,
  40.                 'class'        => 'form-control',
  41.                 'placeholder'  => 'name'
  42.             ]
  43.         ));
  44.         $builder->add('firstnameAr'     ,null, array(
  45.             'label'    => 'first name',
  46.             'required' => true,
  47.             'attr'     => [
  48.                 'validate-msg' => $nameValidation,
  49.                 'class'        => 'form-control',
  50.                 'placeholder'  => 'name'
  51.             ]
  52.         ));
  53.         $builder->add('fourthnameAr',null, array(
  54.             'label'    => 'fourth name',
  55.             'required' => true,
  56.             'attr'     => ['class' => 'form-control margin-bottom-20''validate-msg' => $required_field]
  57.         ));
  58.         $builder->add('identificationNumber',null, array(
  59.             'label'       => 'Identification number',
  60.             'required'    => true,
  61.             'constraints' => array(
  62.                 new Length(array('min' => 10'max' => 10)),
  63.                 new Regex('/^(1|2)[0-9]{9}$/')
  64.             ),
  65.             'attr'        => [
  66.                 'minlength'    => 10,
  67.                 'maxlength'    => 10,
  68.                 'pattern'      => '^(1|2)[0-9]{9}$',
  69.                 'validate-msg' => $idNumValidation,
  70.                 'class'        => 'form-control',
  71.                 'placeholder'  => 'Identification number'
  72.             ]
  73.         ));
  74.     }
  75.     /**
  76.      * {@inheritdoc}
  77.      *
  78.      * @param OptionsResolver $resolver
  79.      */
  80.     public function configureOptions(OptionsResolver $resolver)
  81.     {
  82.         $resolver->setDefaults(array(
  83.             'data_class'         => UserIdentityInfo::class,
  84.             'locale'             => 'en',
  85.             'translation_domain' => 'clients'
  86.         ));
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      *
  91.      * @return null|string
  92.      */
  93.     public function getBlockPrefix()
  94.     {
  95.         return 'appbundle_useridentityinfo_registration';
  96.     }
  97. }