Skip to content

Instantly share code, notes, and snippets.

@rufinus
Last active August 29, 2015 14:12
Show Gist options
  • 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';
}
}
@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