-
-
Save Clindbergh/547997987d350457e792 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Date: 30-Sep-14 | |
* Time: 14:15 | |
*/ | |
use Doctrine\ORM\EntityManager; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\FormInterface; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
class TagTypeExtension2 extends AbstractType | |
{ | |
private $em; | |
function __construct(EntityManager $em) | |
{ | |
$this->em = $em; | |
} | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
$view->vars['select2'] = $options['select2']; | |
$view->vars['max_choice'] = $options['max_choice']; | |
$view->vars['allow_new'] = $options['allow_new']; | |
$view->vars['selected'] = $options['selected']; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
if ($options['select2']) { | |
echo "<!--SELECT2-->"; | |
$builder->addModelTransformer(new ObjectListToStringTransformer($this->em, | |
[ | |
'class' => $options['class'], | |
'property' => $options['property'], | |
'delimiter' => ',' | |
] | |
) | |
); | |
/* $builder->addEventListener(FormEvents::PRE_SUBMIT, | |
function (FormEvent $event) use ($options) { | |
$optionsTransformer = [ | |
'class' => $options['class'], | |
'property' => $options['property'], | |
'delimiter' => ',' | |
]; | |
$event->setData((new ObjectListToStringTransformer($this->em, $optionsTransformer | |
))->reverseTransform($event->getData()[0])); | |
} | |
);*/ | |
} | |
// parent::buildForm($builder, $options); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'select2' => false, | |
'max_choice' => 0, | |
'allow_new' => false, | |
'selected' => array(), | |
// 'constraints' => array(new NotBlank(array('message' => '.'))) | |
// 'mapped' => function (Options $options) { | |
// return !$options['select2']; | |
// } | |
) | |
); | |
} | |
public function getParent() | |
{ | |
return 'entity'; | |
} | |
/** | |
* Returns the name of this type. | |
* | |
* @return string The name of this type | |
*/ | |
public function getName() | |
{ | |
return 'tagType_entity'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment