<?php
namespace App\Form;
use App\Entity\Order;
use App\Entity\Template;
use Eckinox\TinymceBundle\Form\Type\TinymceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\NotBlank;
class OrderFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('deliveryFirstname', TextType::class, [
'required' => false,
'label' => 'First name',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryLastname', TextType::class, [
'required' => false,
'label' => 'Last name',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryCountry', TextType::class, [
'required' => false,
'label' => 'Country',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryCity', TextType::class, [
'required' => false,
'label' => 'City',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryZipcode', TextType::class, [
'required' => false,
'label' => 'Zipcode',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryStreet', TextType::class, [
'required' => false,
'label' => 'Street',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
])
->add('deliveryStreet2', TextType::class, [
'label' => 'Apt. nr., floor',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
'required' => false,
])
->add('billingFirstname', TextType::class, [
'required' => true,
'label' => 'First name',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte vaše jméno',
]),
],
'mapped' => false,
])
->add('billingLastname', TextType::class, [
'required' => true,
'label' => 'Last name',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte vaše příjmení',
]),
],
'mapped' => false,
])
->add('billingCountry', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte zemi',
]),
],
'label' => 'Country',
'mapped' => false,
])
->add('billingCity', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte město',
]),
],
'label' => 'City',
'mapped' => false,
])
->add('billingZipcode', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte PSČ',
]),
],
'label' => 'Zipcode',
'mapped' => false,
])
->add('billingStreet', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte adresu',
]),
],
'label' => 'Street',
'mapped' => false,
])
->add('billingStreet2', TextType::class, [
'label' => 'Apt. nr., floor',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'mapped' => false,
'required' => false,
])
->add('deliveryEmail', EmailType::class, [
'required' => false,
'label' => 'Your e-mail address',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte emailovou adresu',
]),
],
'mapped' => false,
])
->add('deliveryPhone', NumberType::class, [
'required' => false,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte telefonní číslo',
]),
],
'label' => 'Phone number',
'mapped' => false,
])
->add('billingEmail', EmailType::class, [
'required' => true,
'label' => 'Your e-mail address',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte emailovou adresu',
]),
],
'mapped' => false,
])
->add('billingPhone', NumberType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte telefonní číslo',
]),
],
'label' => 'Phone number',
'mapped' => false,
])
->add('text', TinymceType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'attr' => [
'toolbar' => 'undo redo | casechange blocks | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | a11ycheck'
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte text zprávy',
]),
],
'label' => 'Message text',
'mapped' => false,
])
->add('deliveryDate', DateType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3 js-datepicker',
],
'constraints' => [
new NotBlank([
'message' => 'Vyberte přibližné datum doručení',
]),
],
'label' => 'Delivery date',
'widget' => 'single_text',
'html5' => false,
'mapped' => false,
'format' => 'dd.mm.yyyy',
])
->add('code', TextType::class, [
'label' => 'Sales code',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'required' => false,
])
->add('terms', CheckboxType::class, [
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Pro dokončení objednávky musíte souhlasit s podmínkami.',
]),
],
'required' => true,
'label' => 'Souhlasím s <a href="/general-terms-and-conditions">obchodními podmínkami</a> této služby.',
'label_html' => true,
])
->add('template', EntityType::class, [
'class' => Template::class,
'choice_label' => 'name',
'choice_value' => 'path',
'mapped' => false,
'required' => true,
])
->add('deliveryAddressCheckbox', CheckboxType::class, [
'mapped' => false,
'label' => 'Fakturační údaje se shodují s doručovacími',
'label_html' => true,
'required' => false,
])
->add('price', NumberType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
'label' => 'Koncová částka',
'required' => false,
])
->add('orderButton', SubmitType::class, [
'label' => 'Objednat'
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Order::class,
// enable/disable CSRF protection for this form
'csrf_protection' => true,
// the name of the hidden HTML field that stores the token
'csrf_field_name' => '_token',
// an arbitrary string used to generate the value of the token
// using a different string for each form improves its security
'csrf_token_id' => 'task_item',
]);
}
}