<?php
namespace App\Form;
use App\Entity\Company;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use App\Form\CompanyLocationType;
use App\Form\CompanyDefaultShippingType;
use App\Entity\CompanyLocation;
use App\Entity\CompanyDefaultShipping;
use App\Form\Type\PhoneType;
use App\Form\Type\EditorType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
class CompanyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if(!empty($builder->getData())){
if(empty($builder->getData()->getDefaultShipping())){
$defaultShippingData = new companyDefaultShipping();
$builder->getData()->setDefaultShipping($defaultShippingData);
}else
$defaultShippingData = $builder->getData()->getDefaultShipping();
}else
$defaultShippingData = new companyDefaultShipping();
$builder
->add('termsAcceptance', CheckboxType::class, array(
'empty_data' => false,
'required' => true,
'attr' => array('class' => 'checkbox-only'),
))
->add('name', TextType::class, array(
'label' => 'Nom de la compagnie'
))
->add('description', EditorType::class, array(
'label' => 'Description',
'type' => 'simple'
))
->add('showPublicly', CheckboxType::class, array(
'required' => false,
'label' => 'Afficher la boutique sur le site',
'attr' => array('class' => 'switch-button checkbox-only'),
))
->add('website', TextType::Class, array(
'attr' => array(
'placeholder' => 'http://www.exemple.com'
),
'empty_data' => '',
'required' => false
))
->add('customUrl', TextType::Class, array(
'label' => 'Lien boutique maturin https://www.maturin.ca/',
'required' => false
))
->add(
$builder->create('mainLocation', FormType::class,
array(
'by_reference' => true,
'empty_data' => new CompanyLocation(),
'data_class' => CompanyLocation::class,
'label' => false
))
->add('pickUp', CheckBoxType::class, array(
'label' => 'Faire de cet établissement un lieu de cueillette?',
'attr' => array('class' => 'switch-button checkbox-only'),
'required' => false
))
->add('civicNumber')
->add('streetName')
->add('city')
->add('province', ChoiceType::class, array(
'label' => 'Province',
'placeholder' => 'Choisir',
'choices' => array(
'Alberta'=> 'AB',
'Colombie-Britannique' => 'BC',
'Île-du-Prince-Édouard' => 'PE',
'Manitoba' => 'MB',
'Nouveau-Brunswick' => 'NB',
'Nouvelle-Écosse' => 'NS',
'Nunavut' => 'NU',
'Ontario' => 'ON',
'Québec' => 'QC',
'Saskatchewan' => 'SK',
'Terre-Neuve-et-Labrador' => 'NL',
'Territoires du Nord-Ouest' => 'NT',
'Yukon' => 'YT'
)
))
->add('region', EntityType::class, array(
'label' => 'Région',
'placeholder' => 'Choisir',
'class' => 'App\Entity\Region',
'choice_label' => 'name',
'required' => true,
))
->add('zipCode')
->add('country', CountryType::class, array(
'preferred_choices' => array('CA','US')
))
->add('phone', PhoneType::Class)
->add('phoneExtension', TextType::Class, array('label' => 'Ext:', 'required' => false))
->add('mobilePhone', PhoneType::Class, array(
'required' => false
))
->add('email', EmailType::Class, array(
'required' => false
))
->add('notesForBuyer', TextareaType::class, array(
'label' => 'Veuillez entrer les informations (Date, Heure, Jour de délai moyen etc...)',
'required' => false
))
->add('showPublic', CheckboxType::class, array(
'required' => false,
'label' => 'Afficher publiquement',
'attr' => array('class' => 'switch-button checkbox-only'),
))
)
->add('otherLocations', CollectionType::class,array(
'entry_type' => CompanyLocationType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
'label' => false
))
->add('image', FileType::Class, array(
'label' => 'Logo',
'data_class' => null,
'required' => false,
))
->add('banner', FileType::Class, array(
'data_class' => null,
'required' => false,
))
->add('speciality', EditorType::Class,
array(
'required' => false
)
)
->add('customSaleConditions', CheckBoxType::class, array(
'label' => 'Souhaitez-vous personnaliser les conditions générales de vente ?',
'attr' => array('class' => 'switch-button checkbox-only'),
'required' => false
))
->add('conditionsShipping', TextareaType::Class,
array(
'required' => false,
'label' => 'Livraison et cueillette',
)
)
->add('conditionsReturn', TextareaType::Class,
array(
'required' => false,
'label' => 'Retour et échange',
)
)
->add('conditionsCancel', TextareaType::Class,
array(
'required' => false,
'label' => 'Annulation',
)
)
->add('defaultShipping', CompanyDefaultShippingType::class, array('data' => $defaultShippingData))
->add('submit', SubmitType::Class,
array(
'label' => 'Soumettre'
)
)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Company::class,
'csrf_protection' => false//Create some weird bug on this form
]);
}
}