user331157
user331157

Reputation: 3

symfony 6 form choice_filter application

I'm using Symfony 6 to filter an entity in a form type. My problem is 'choice_filter' , I understand documentation, I test with simple application article and category and I want a select with not all category. I would like one or more category in select. In follow my last test with only one in select.

Error: Could not load type "App\Form\ChoiceType": class does not exist. In my controller:

$article = new Article();
$form = $this->createForm(ArticleType::class, $article);

ArticleTYpe:

public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
         ->add('category', EntityType::class, [
            'class' => Category::class,
            'choice_label' => 'name category',
            'choice_filter' => ChoiceList::filter(
                $this,
                function ($category) {
                    if ($category instanceof Category) {
                        return $category->getId(1);
                    }
                    return false;
                }
            )
        ])
            ;
    }

Upvotes: 0

Views: 392

Answers (0)

Related Questions