<?php
namespace App\Form\Customer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Address;
use App\Entity\BillingAddress;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Formular agreguje formularce PackageCalculation a DeliveryAddressType a umozuje spolecny formular odeslat
*/
class SimpleOrderType extends AbstractType
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('calculation', PackageCalculation::class, [
'entityManager' => $options['entityManager']
])
->add('deliveryTo', AddressType::class, [
'entityManager' => $options['entityManager'],
'addressType' => AddressType::TYPE_DELIVERY_FRONTEND,
'data' => new Address(),
'countryIso' => $options['deliveryCountry'],
'renderCountry' => true
])
->add('returnTo', AddressType::class, [
'entityManager' => $options['entityManager'],
'addressType' => AddressType::TYPE_RETURN,
'data' => new Address(),
'countryIso' => 'cz',
])
->add('billing', AddressType::class, [
'entityManager' => $options['entityManager'],
'addressType' => AddressType::TYPE_BILLING,
'data' => new BillingAddress(),
'countryIso' => 'cz',
'required' => false,
])
->add(
'contentDescription',
TextType::class,
[
'label' => $this->translator->trans('Obsah balíku:'),
'required' => true,
'constraints' => [
new NotBlank([
'message' => $this->translator->trans('Pole obsah balíku nesmí být prázdné!')
]),
new Length([
'min' => $minContantLength = 2,
'max' => $maxContantLength = 255,
'minMessage' => $this->translator->trans(
'Pole obsah balíku musí být dlouhé %min% až %max% znaků!',
['%min%' => $minContantLength, '%max%' =>$maxContantLength],
'customer'
),
])
]
]
)
->add(
'submit',
SubmitType::class,
[
'label' => $this->translator->trans('ODESLAT OBJEDNÁVKU'),
'attr' => ['class' => 'btn btn-success btn-lg']
]
);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired('entityManager');
$resolver->setRequired('deliveryCountry'); // iso pro vychozi zemi doruceni
}
}