Last active
June 1, 2018 10:15
-
-
Save ADCPD/1b3e63382d112909764a2ef2743b1b98 to your computer and use it in GitHub Desktop.
How to use Radio Field with EntityType Symfony 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DemandeBundle\Form; | |
class DemandeType extends AbstractType { | |
/** @var EntityManagerInterface $em */ | |
private $em; | |
/** | |
* | |
* @param EntityManagerInterface $em | |
*/ | |
public function __construct(EntityManagerInterface $em) { | |
$this->em = $em; | |
} | |
/** | |
* @param FormBuilderInterface $builder | |
* @param array $options | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) { | |
$builder | |
->add('typedecision', EntityType::class, array( | |
'label' => 'Type of support', | |
'label_attr' => array( | |
'for' => 'demandes_demande_type_decision', | |
'class' => 'radio-inline' | |
), | |
'attr' => array( | |
), | |
'required' => false, | |
'read_only' => false, | |
'class' => 'DemandesBundle:Decision', | |
'query_builder' => function (EntityRepository $er) { | |
return $er->createQueryBuilder('u') | |
->orderBy('u.libelle', 'ASC'); | |
}, | |
'expanded' => true, | |
'property' => 'libelle', | |
)); | |
} | |
/** | |
* {@inheritdoc} | |
* @param OptionsResolver $resolver | |
*/ | |
public function configureOptions(OptionsResolver $resolver) { | |
$resolver->setDefaults(array( | |
'data_class' => 'DemandesBundle\Entity\Demande' | |
)); | |
} | |
/** | |
* {@inheritdoc} | |
* @return string | |
*/ | |
public function getName() { | |
return "demandes_obj_demande_form"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment