Skip to content

Instantly share code, notes, and snippets.

@ollo-ride-nico
Created January 24, 2018 16:03
Show Gist options
  • Save ollo-ride-nico/6ed798648a86e7bb16aa05332f16e700 to your computer and use it in GitHub Desktop.
Save ollo-ride-nico/6ed798648a86e7bb16aa05332f16e700 to your computer and use it in GitHub Desktop.
class TricksType extends AbstractType
{
private $entitymanager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entitymanager = $entityManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// On affiche les champs du builder
$builder
->add('nom', TextType::class)
->add('description', TextareaType::class)
->add('groupe', GroupeAddType::class)
->add('image', CollectionType::class, array(
'entry_type' => ImageAddType::class,
'entry_options' => array('data_class' => Image::class, 'label' => false),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
/*'mapped' => false,*/
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Tricks::class
));
}
}
class ImageAddType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('alt', TextType::class, array('label' => 'Mot clefs(alt)'))
->add('url', FileType::class, array('label' => 'Ajouter une image:',
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Image::class,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment