Last active
August 29, 2015 14:12
-
-
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?
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 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 <[email protected]> | |
* | |
* @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'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OptionsResolverInterface needs to stay in the method signature. That will change in 3.0.