1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('titre', TextType::class, [
])
->add('application', EntityType::class, [
'class' => 'AppBundle;Application'
])
->add('details', CollectionType::class, [
'label' => false,
'entry_type' => DetailsType::class,
'allow_add' => true,
'allow_delete' => true,
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'AppBundle\Entity\Ticket',
'constraints'=>new Callback(array('callback'=>function($ticket,ExecutionContextInterface $context){
if($ticket->getApplication()) {
foreach ($ticket->getDetails() as $detail) {
if ($detail->getNomServeur()) {
$serveurTrouve = false;
// Controle pour vérifier que les serveurs saisie sont des serveurs de l'application
foreach ($ticket->getApplication()->getServeurs() as $serveur) {
if ($serveur->getName() === $detail->getNomServeur()) {
$serveurTrouve = true;
}
}
if(!$serveurTrouve) {
$context->buildViolation('Un des serveur n'est pas dans l\'application')
->atPath('application')
->addViolation()
;
}
}
}
}
})),
]);
} |
Partager