* * 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\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * @author Amine Zaghdoudi */ class ChoiceTypeExtension extends AbstractTypeExtension { /** * NEXT_MAJOR: Remove method, when bumping requirements to SF 2.7+. * * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $this->configureOptions($resolver); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $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']; } /** * {@inheritdoc} */ public function getExtendedType() { /* * NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should * simply be return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; */ return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\ChoiceType' : 'choice'; } }