Skip to content

Instantly share code, notes, and snippets.

@gaetanhauray
Created June 1, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaetanhauray/2b46b22b31c66e8d699e1367e325a21d to your computer and use it in GitHub Desktop.
Save gaetanhauray/2b46b22b31c66e8d699e1367e325a21d to your computer and use it in GitHub Desktop.
<?php
namespace LB\LBBundle\Form\FormBuilder\Coregistration;
use LB\Common\VO\Coregistration\CoregistrationVO;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* formulaire d'une coregistration
* @author Gaetan
*/
class CoregistrationType extends AbstractType {
/**
* (non-PHPdoc)
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
/**
* On affiche une coche pour chaque coregistration
*/
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) {
/** @var CoregistrationVO $coregistration */
$coregistration = $event->getData();
$form = $event->getForm();
$form->add(
"accepted",
ChoiceType::class,
array(
'choices' => array(
$coregistration->getSentence() => true
),
'choices_as_values' => true,
'attr' => array(
'class' => 'coregistration',
),
'label' => false,
'multiple' => true,
'expanded' => true,
)
);
}
);
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(
array(
'data_class' => 'LB\Common\VO\Coregistration\CoregistrationVO',
'csrf_protection' => true,
'csrf_field_name' => '_token'
)
);
}
}
<?php
namespace LB\Common\VO\Coregistration;
/**
* Vo Représentant une Coregistration de projet
* @author Gaetan
*/
class CoregistrationVO {
/**
* La phrase écrite
* @var string
*/
private $sentence;
/**
* Le logo lié à l'offre
* @var string
*/
private $logoUrl;
/**
* L'offre est-elle activée
* @var bool
*/
private $enable = false;
/**
* L'offre a t elle été coché par le particulier
* @var bool
*/
private $accepted = false;
//Getter & setter
}
<?php
namespace LB\LBBundle\Form\FormBuilder\Project;
use LB\LBBundle\Form\FormBuilder\Coregistration\CoregistrationType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
/**
*
* @author Gaetan
*/
class CreateProjectLPIdentityForm extends AbstractType {
/**
* (non-PHPdoc)
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
/* Name */
$builder->add(
"name",
TextType::class,
array(
'label' => 'project.informations.last_name',
'label_attr' => array(
'class' => 'control-label'
),
'attr' => array(
'placeholder' => 'Nom (ex: Morin, Dubois)',
'class' => 'form-control',
'autocomplete' => 'on'
),
'required'=>true,
'constraints' => array(
new NotBlank(array('message' => 'name.error.missing')),
new Length(array('minMessage' => 'name.error.too_short','min' => 3))
)
)
);
/**
* Coregistrations
*/
$builder->add('coregistrations', CollectionType::class, array(
'entry_type' => CoregistrationType::class
));
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(
array(
'data_class' => 'LB\LBBundle\VO\Project\ProjectLandingPageVO',
'csrf_protection' => true,
'csrf_field_name' => '_token',
'expandedChoiceType' => false
)
);
}
}
<?php
namespace LB\LBBundle\VO\Project;
use LB\Common\VO\AbstractVO;
use LB\Common\VO\Coregistration\CoregistrationVO;
use LB\Common\VO\Project\Form\CreateProjectFormVO;
use LB\Common\VO\Project\ProjectFieldVO;
/**
* VO d'un projet créer par les Landingpages
* @author Gaetan
*/
class ProjectLandingPageVO extends CreateProjectFormVO {
/**
* @var string
*/
private $name;
/**
* Les coregistrations acceptées par le particulier
* @var CoregistrationVO[]
*/
private $coregistrations;
//Getter & Setter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment