src/Form/Customer/SimpleOrderType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form\Customer;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use App\Entity\Address;
  9. use App\Entity\BillingAddress;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. /**
  14.  * Formular agreguje formularce PackageCalculation a DeliveryAddressType a umozuje spolecny formular odeslat
  15.  */
  16. class SimpleOrderType extends AbstractType
  17. {
  18.     private TranslatorInterface $translator;
  19.     public function __construct(TranslatorInterface $translator)
  20.     {
  21.         $this->translator $translator;
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.             ->add('calculation'PackageCalculation::class, [
  27.                 'entityManager' => $options['entityManager']
  28.             ])
  29.             ->add('deliveryTo'AddressType::class, [
  30.                 'entityManager' => $options['entityManager'],
  31.                 'addressType' => AddressType::TYPE_DELIVERY_FRONTEND,
  32.                 'data' => new Address(),
  33.                 'countryIso' => $options['deliveryCountry'],
  34.                 'renderCountry' => true
  35.             ])
  36.             ->add('returnTo'AddressType::class, [
  37.                 'entityManager' => $options['entityManager'],
  38.                 'addressType' => AddressType::TYPE_RETURN,
  39.                 'data' => new Address(),
  40.                 'countryIso' => 'cz',
  41.             ])
  42.             ->add('billing'AddressType::class, [
  43.                 'entityManager' => $options['entityManager'],
  44.                 'addressType' => AddressType::TYPE_BILLING,
  45.                 'data' => new BillingAddress(),
  46.                 'countryIso' => 'cz',
  47.                 'required' => false,
  48.             ])
  49.             ->add(
  50.                 'contentDescription',
  51.                 TextType::class,
  52.                 [
  53.                     'label' => $this->translator->trans('Obsah balíku:'),
  54.                     'required' => true,
  55.                     'constraints' => [
  56.                         new NotBlank([
  57.                             'message' => $this->translator->trans('Pole obsah balíku nesmí být prázdné!')
  58.                         ]),
  59.                         new Length([
  60.                             'min' => $minContantLength 2,
  61.                             'max' => $maxContantLength 255,
  62.                             'minMessage' => $this->translator->trans(
  63.                                 'Pole obsah balíku musí být dlouhé %min%  až %max% znaků!',
  64.                                 ['%min%' => $minContantLength'%max%' =>$maxContantLength],
  65.                                 'customer'
  66.                             ),
  67.                         ])
  68.                     ]
  69.                 ]
  70.             )
  71.             ->add(
  72.                 'submit',
  73.                 SubmitType::class,
  74.                 [
  75.                     'label' => $this->translator->trans('ODESLAT OBJEDNÁVKU'),
  76.                     'attr' => ['class' => 'btn btn-success btn-lg']
  77.                 ]
  78.             );
  79.     }
  80.     public function configureOptions(OptionsResolver $resolver): void
  81.     {
  82.         $resolver->setRequired('entityManager');
  83.         $resolver->setRequired('deliveryCountry'); // iso pro vychozi zemi doruceni
  84.     }
  85. }