Commit beddfc7b authored by Mat's avatar Mat

personnalisation des formulaires

parent 6ae8bc09
......@@ -51,11 +51,22 @@ class Association
/**
* @var Membre[]
*
*
* @ORM\OneToMany(targetEntity="AssoBundle\Entity\Membre", mappedBy="association")
*/
private $membres;
/**
* @return string
*/
public function getFullName()
{
return $this->nom . " [" . $this->email . "]";
}
/**
* Get id
*
......@@ -162,4 +173,3 @@ class Association
return $this->tva;
}
}
......@@ -7,6 +7,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use AssoBundle\Entity\Membre;
......@@ -21,13 +22,69 @@ class MembreType extends AbstractType
{
parent::buildForm($builder, $options);
$builder->add('prenom', TextType::class);
$builder->add('nom', TextType::class);
$builder->add('email', TextType::class);
/** @var Membre $data */
$data = $builder->getData();
// UTILE !!
// ^^ permet par exemple d'utiliser
// 'data'=>$data->getAssociation()->getTva(),
// l'annotation permet à l'IDE de connaitre le type des données
// va de pair avec mapped=false
if ($data->getId() !== null) {
$builder->add('country', CountryType::class, array(
'mapped' => false,
'data' => ($data->getAssociation() === null) ? null : $data->getAssociation()->getTva()
));
}
// ^^ une condition pour éviter des erreurs
$builder->add('prenom', TextType::class, array(
'label_attr' => array(
'class'=>'super-label label-common'
),
'attr' => array(
'class' => 'custom_input',
'min'=>"5",
'max'=>"255",
),
'label' => 'Prénom' // peut prendre 'false'
));
$builder->add('nom', TextType::class, array(
'label_attr' => array(
'class'=>'super-label label-common'
),
'attr' => array(
'class' => 'custom_input',
'min'=>"5",
'max'=>"255",
),
'label' => 'Nom'
));
$builder->add('email', TextType::class, array(
'label_attr' => array(
'class'=>'super-label label-common'
),
'attr' => array(
'class' => 'custom_input',
'min'=>"5",
'max'=>"100",
'step'=>"1",
),
'data'=>"alias@email.tld",
'required' => false,
'label' => 'Adresse email'
));
$builder->add('association', EntityType::class, array(
'class' => Association::class,
'choice_label' => 'nom'
'choice_label' => 'getFullName' // le texte du select
));
$builder->add('Enregistrer', SubmitType::class);
}
......
......@@ -27,6 +27,9 @@
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
{{ dump() }}
{# Debug
{{ dump() }}
#}
</body>
</html>
......@@ -269,3 +269,8 @@ form small {
color: #a7a7a7;
float: right;
}
form label.required:after {
content: " * ";
color: darkred;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment