Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $taxonomies = $this->taxonomyRepository->findAll();
     $builder->addModelTransformer(new $options['model_transformer']['class']($taxonomies, $options['model_transformer']['save_objects']));
     foreach ($taxonomies as $taxonomy) {
         /* @var $taxonomy TaxonomyInterface */
         $builder->add($taxonomy->getId(), 'choice', array('choice_list' => new ObjectChoiceList($this->taxonRepository->getTaxonsAsList($taxonomy), null, array(), null, 'id'), 'multiple' => $options['multiple'], 'label' => $taxonomy->getName()));
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $choiceList = function (Options $options) {
         $taxons = $this->taxonRepository->getTaxonsAsList($options['taxonomy']);
         if (null !== $options['filter']) {
             $taxons = array_filter($taxons, $options['filter']);
         }
         return new ObjectChoiceList($taxons, null, array(), null, 'id');
     };
     $resolver->setDefaults(array('choice_list' => $choiceList))->setRequired(array('taxonomy', 'filter'))->setAllowedTypes('taxonomy', TaxonomyInterface::class)->setAllowedTypes('filter', ['callable', 'null']);
 }