src/Form/UserType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Commission;
  4. use App\Entity\User;
  5. use App\Repository\CommissionRepository;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. class UserType extends AbstractType
  16. {
  17.     private TranslatorInterface $translator;
  18.     public function __construct(TranslatorInterface $translator)
  19.     {
  20.         $this->translator $translator;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $builder
  25.             ->add('username'TextType::class, [
  26.                 'label'    => $this->translator->trans('username') . '*',
  27.                 'attr'     => [
  28.                     'class'       => 'form-control mb-3 border border-danger',
  29.                     'placeholder' => $this->translator->trans('username') . '*',
  30.                 ],
  31.                 'required' => true,
  32.             ])
  33.             ->add('email'EmailType::class, [
  34.                 'label'    => $this->translator->trans('email') . '*',
  35.                 'attr'     => [
  36.                     'class'       => 'form-control mb-3 border border-danger',
  37.                     'placeholder' => $this->translator->trans('email') . '*',
  38.                 ],
  39.                 'required' => true,
  40.             ])
  41.             ->add('password'TextType::class, [
  42.                 'label'      => $this->translator->trans('passwd') . '*',
  43.                 'attr'       => [
  44.                     'class'       => 'form-control mb-3 border border-danger',
  45.                     'placeholder' => $this->translator->trans('passwd') . '*',
  46.                 ],
  47.                 'empty_data' => '',
  48.                 'required'   => true,
  49.             ])
  50.             ->add('company_name'TextType::class, [
  51.                 'label'    => $this->translator->trans('company') . '*',
  52.                 'attr'     => [
  53.                     'class'       => 'form-control mb-3 border border-danger',
  54.                     'placeholder' => $this->translator->trans('company') . '*',
  55.                 ],
  56.                 'required' => true,
  57.             ])
  58.             ->add('vat_id'TextType::class, [
  59.                 'label'    => $this->translator->trans('vatId'),
  60.                 'attr'     => [
  61.                     'class'       => 'form-control mb-3',
  62.                     'placeholder' => $this->translator->trans('vatId'),
  63.                 ],
  64.                 'required' => false,
  65.             ])
  66.             ->add('salutation'ChoiceType::class, [
  67.                 'label'    => $this->translator->trans('salutation'),
  68.                 'choices'  => [
  69.                     $this->translator->trans('mr')  => $this->translator->trans('mr'),
  70.                     $this->translator->trans('mrs') => $this->translator->trans('mrs'),
  71.                 ],
  72.                 'attr'     => [
  73.                     'class'       => 'form-select mb-3',
  74.                     'placeholder' => $this->translator->trans('salutation'),
  75.                 ],
  76.                 'required' => false,
  77.             ])
  78.             ->add('first_name'TextType::class, [
  79.                 'label'    => $this->translator->trans('firstName') . '*',
  80.                 'attr'     => [
  81.                     'class'       => 'form-control mb-3 border border-danger',
  82.                     'placeholder' => $this->translator->trans('firstName') . '*',
  83.                 ],
  84.                 'required' => true,
  85.             ])
  86.             ->add('last_name'TextType::class, [
  87.                 'label'    => $this->translator->trans('lastName') . '*',
  88.                 'attr'     => [
  89.                     'class'       => 'form-control mb-3 border border-danger',
  90.                     'placeholder' => $this->translator->trans('lastName') . '*',
  91.                 ],
  92.                 'required' => true,
  93.             ])
  94.             ->add('street'TextType::class, [
  95.                 'label'    => $this->translator->trans('streetAndNumber') . '*',
  96.                 'attr'     => [
  97.                     'class'       => 'form-control mb-3 border border-danger',
  98.                     'placeholder' => $this->translator->trans('streetAndNumber') . '*',
  99.                 ],
  100.                 'required' => true,
  101.             ])
  102.             ->add('street_additional'TextType::class, [
  103.                 'label'    => $this->translator->trans('streetAdditional'),
  104.                 'attr'     => [
  105.                     'class'       => 'form-control mb-3',
  106.                     'placeholder' => $this->translator->trans('streetAdditional'),
  107.                 ],
  108.                 'required' => false,
  109.             ])
  110.             ->add('zip_code'TextType::class, [
  111.                 'label'    => $this->translator->trans('zipCode') . '*',
  112.                 'attr'     => [
  113.                     'class'       => 'form-control mb-3 border border-danger',
  114.                     'placeholder' => $this->translator->trans('zipCode') . '*',
  115.                 ],
  116.                 'required' => true,
  117.             ])
  118.             ->add('city'TextType::class, [
  119.                 'label'    => $this->translator->trans('city') . '*',
  120.                 'attr'     => [
  121.                     'class'       => 'form-control mb-3 border border-danger',
  122.                     'placeholder' => $this->translator->trans('city') . '*',
  123.                 ],
  124.                 'required' => true,
  125.             ])
  126.             ->add('phone'TextType::class, [
  127.                 'label'    => $this->translator->trans('phone') . '*',
  128.                 'attr'     => [
  129.                     'class'       => 'form-control mb-3 border border-danger',
  130.                     'placeholder' => $this->translator->trans('phone') . '*',
  131.                 ],
  132.                 'required' => true,
  133.             ])
  134.             ->add('country'ChoiceType::class, [
  135.                 'label'    => $this->translator->trans('country') . '*',
  136.                 'choices'  => [
  137.                     $this->translator->trans('germany')      => $this->translator->trans('germany'),
  138.                     $this->translator->trans('austria')      => $this->translator->trans('austria'),
  139.                     $this->translator->trans('switzerland')  => $this->translator->trans('switzerland'),
  140.                     $this->translator->trans('lichtenstein') => $this->translator->trans('lichtenstein'),
  141.                     $this->translator->trans('spain')        => $this->translator->trans('spain'),
  142.                     $this->translator->trans('uk')           => $this->translator->trans('uk'),
  143.                 ],
  144.                 'attr'     => [
  145.                     'class'       => 'form-select mb-3 border border-danger',
  146.                     'placeholder' => $this->translator->trans('country') . '*',
  147.                 ],
  148.                 'required' => true,
  149.             ])
  150.             ->add('commission'EntityType::class, [
  151.                 'class'         => Commission::class,
  152.                 'placeholder'   => 'txtFormSelect',
  153.                 'required'      => false,
  154.                 'query_builder' => function (CommissionRepository $commissionRepository) {
  155.                     return $commissionRepository->createQueryBuilder('c')
  156.                         ->where('c.is_active = 1')
  157.                         ->orderBy('c.commission_name''ASC');
  158.                 },
  159.                 'attr'          => [
  160.                     'class'       => 'form-select mb-3 border border-danger',
  161.                     'placeholder' => $this->translator->trans('country') . '*',
  162.                 ],
  163.             ])
  164.             ->add('bank_name'TextType::class, [
  165.                 'label'    => $this->translator->trans('bankName') . '*',
  166.                 'attr'     => [
  167.                     'class'       => 'form-control mb-3 border border-danger bank',
  168.                     'placeholder' => $this->translator->trans('bankName') . '*',
  169.                 ],
  170.                 'required' => true,
  171.             ])
  172.             ->add('bank_account_name'TextType::class, [
  173.                 'label'    => $this->translator->trans('accountOwner') . '*',
  174.                 'attr'     => [
  175.                     'class'       => 'form-control mb-3 border border-danger bank',
  176.                     'placeholder' => $this->translator->trans('accountOwner') . '*',
  177.                 ],
  178.                 'required' => true,
  179.             ])
  180.             ->add('iban'TextType::class, [
  181.                 'label'    => $this->translator->trans('iban') . '*',
  182.                 'attr'     => [
  183.                     'class'       => 'form-control mb-3 border border-danger bank',
  184.                     'placeholder' => $this->translator->trans('iban') . '*',
  185.                 ],
  186.                 'required' => true,
  187.             ])
  188.             ->add('bic'TextType::class, [
  189.                 'label'    => $this->translator->trans('bic') . '*',
  190.                 'attr'     => [
  191.                     'class'       => 'form-control mb-3 border border-danger bank',
  192.                     'placeholder' => $this->translator->trans('bic') . '*',
  193.                 ],
  194.                 'required' => true,
  195.             ])
  196.             ->add('is_invoiced_by_shop'CheckboxType::class, [
  197.                 'label' => $this->translator->trans('lang.isInvoicedByShop'),
  198.                 'required' => false,
  199.             ])
  200.         ;
  201.     }
  202.     public function configureOptions(OptionsResolver $resolver): void
  203.     {
  204.         $resolver->setDefaults([
  205.                                    'data_class' => User::class,
  206.                                ]);
  207.     }
  208. }