Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between configureOptions and setDefaultOptions ina form in Symfony 2

Tags:

forms

php

symfony

I recently came across a problem that I solved. To solve this problem, I ended using setDefaultOptions insted of configureOptions in one of my form. The thing is that it got me asking, what's the difference between those two functions?

Here is the way they both look like in my form:

<?php

namespace AdminBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
//use Symfony\Component\OptionsResolver\OptionsResolver;

Class ProjetIntType extends AbstractType
{

    public function buildForm(FormBuilderInterface $constructeur, array $options)
    {
        $constructeur
        ->add('langue', 'text')
        ->add('nom', 'text')
        ->add('descriptionCours', 'text')
        ->add('descriptionComplete', 'text')
        ->add('roles', 'text')
        ->add('aptitudesDeveloppees', 'text');
    }

    /*public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'PublicBundle\Entity\ProjetInt',
        ));
    }*/

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'PublicBundle\Entity\ProjetInt',
            ));
    }

    public function getName()
    {

        return 'projetInt';

    }

}
like image 969
Kévin Duguay Avatar asked Aug 20 '15 22:08

Kévin Duguay


1 Answers

setDefaultOptions() has been deprecated in favor of configureOptions(). See UPGRADE-3.0.md. configureOptions() was introduced in Symfony 2.7 and will be required in 3.0.

like image 111
geoB Avatar answered Sep 30 '22 16:09

geoB