Skip to content

Instantly share code, notes, and snippets.

@rufinus
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rufinus/4799c87b0c83bf53e865 to your computer and use it in GitHub Desktop.
Save rufinus/4799c87b0c83bf53e865 to your computer and use it in GitHub Desktop.
Symfony FormType <2.6 what is the >=2.6 way? Without needing OptionsResolverInterface?
<?php
namespace Dpanel\Bundle\AdminBundle\Forms;
use Cwd\GenericBundle\Doctrine\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class Mandator Form
*
* @package Dpanel\Bundle\AdminBundle\Forms
* @author Ludwig Ruderstaller <lr@cwd.at>
*
* @DI\Service("dpanel_admin_form_mandator")
* @DI\Tag("form.type")
*/
class MandatorType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*
* @return misc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('foo', 'text', array('label' => 'Foobar'))
->add('save', 'submit', array('label' => 'Save'));
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'validation_groups' => array('default'),
'data_class' => 'Dpanel\Model\Entity\Mandator',
));
}
/**
* @return string
*/
public function getName()
{
return 'dpanel_admin_form_mandator';
}
}
@rufinus
Copy link
Author

rufinus commented Dec 25, 2014

AbstractType uses FormTypeInterface which uses the OptionsResolverInterface.
It seems there is currently now way around it, and i will have to edit all my forms once the interface is finaly removed.

@webmozart
Copy link

OptionsResolverInterface needs to stay in the method signature. That will change in 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment