* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Sonata\AdminBundle\Form\Extension; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * Class ChoiceTypeExtension * * @package Sonata\AdminBundle\Form\Extension * * @author Amine Zaghdoudi */ class ChoiceTypeExtension extends AbstractTypeExtension { /** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $optionalOptions = array('sortable'); if (method_exists($resolver, 'setDefined')) { $resolver->setDefined($optionalOptions); } else { // To keep Symfony <2.6 support $resolver->setOptional($optionalOptions); } } /** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['sortable'] = array_key_exists('sortable', $options) && $options['sortable']; } /** * Returns the name of the type being extended. * * @return string The name of the type being extended */ public function getExtendedType() { return 'choice'; } }