<?php
namespace SymfonyDev\AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type as FT;
use SymfonyDev\AppBundle\Entity\User;
class RegisterType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
$builder
->add('title', FT\ChoiceType::class, array(
'required' => true,
'expanded' => false,
'choices' => array(
User::USER_TITLE_MR => User::USER_TITLE_MR,
User::USER_TITLE_MRS => User::USER_TITLE_MRS,
User::USER_TITLE_MS => User::USER_TITLE_MS,
User::USER_TITLE_MISS => User::USER_TITLE_MISS,
User::USER_TITLE_DR => User::USER_TITLE_DR,
User::USER_TITLE_MX => User::USER_TITLE_MX
)
))
->add('firstName', null, array('required' => true))
->add('lastName', null, array('required' => true))
->add('dateOfBirth', null, array('required' => true, 'widget' => 'single_text', 'format' => 'dd/MM/yyyy'))
->add('email', null, array('required' => true))
->add('plainPassword', FT\RepeatedType::class, array(
'type' => FT\PasswordType::class,
'required' => true,
'invalid_message' => 'Password and Confirm Password should be same.',
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Confirm Password'),
))
->add('website', null, array('required' => false))
->add('workPhone', null, array('required' => true))
->add('mobile', null, array('required' => true))
->add('isNews', null, array('required' => false, 'label' => false))
->add(
'addresses',
FT\CollectionType::class,
array(
'label' => false,
'required' => true,
'allow_add' => true,
'allow_delete' => true,
'entry_type' => AddressType::class,
'prototype' => true,
'error_bubbling' => false,
'by_reference' => false
)
)
;
if ($options['user_type'] == User::USER_USER_TYPE_PRACTITIONER || $options['user_type'] == User::USER_USER_TYPE_STUDENT) {
$builder
->add('registration', null, array('required' => true))
->add('association', null, array('required' => true))
;
}
if ($options['user_type'] == User::USER_USER_TYPE_PRACTITIONER || $options['user_type'] == User::USER_USER_TYPE_STUDENT || $options['user_type'] == User::USER_USER_TYPE_USER) {
$builder
->add('howDidYouFindUs', FT\ChoiceType::class, array(
'constraints' => [
new \Symfony\Component\Validator\Constraints\NotBlank()
],
'label' => false,
'required' => true,
'expanded' => true,
'multiple' => true,
'choices' => array(
'Referral from a colleague'=>'Referral from a colleague',
'Advertisement'=>'Advertisement',
'Internet search'=>'Internet search',
'Event'=>'Event',
'Webinar'=>'Webinar',
'University'=>'University',
'Blog'=>'Blog',
'Acuneeds'=>'Acuneeds',
'San Acupuncture supplies'=>'San Acupuncture supplies',
'Social media'=>'Social media'
)
))
;
}
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'SymfonyDev\AppBundle\Entity\User',
'user_type' => null,
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'symfonydev_appbundle_register';
}
}