Created
April 3, 2019 17:00
-
-
Save ger86/e0c6f8af5a9bf0be86f3770a18ea23bc to your computer and use it in GitHub Desktop.
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 App\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\Form\FormInterface; | |
class Select2Type extends AbstractType { | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
$attr = $view->vars['attr']; | |
$class = isset($attr['class']) ? $attr['class'].' ' : ''; | |
$class .= 'select2'; | |
$attr['class'] = $class; | |
$attr['data-autocomplete-url'] = $attr['data-autocomplete-url']; | |
$view->vars['attr'] = $attr; | |
} | |
public function getParent() { | |
return ChoiceType::class; | |
} | |
public function configureOptions(OptionsResolver $resolver) { | |
$resolver->setDefaults([ | |
'attr' => [ | |
'class' => 'select2', | |
'data-autocomplete-url' => '' | |
] | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment