->add('categories', EntityType::class, [
'class' => Category::class,
'choices' => $categories,
'choice_label' => function (Category $category = null) {
return null !== $category ? str_repeat('--', $category->getLevel()).' '.$category->getTitle() : '';
},
'choice_value' => function (Category $category = null) {
return null !== $category ? $category->getId() : '';
},
'label' => false,
'multiple' => true,
'placeholder' => '- Находится в -',
])
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// Формируем $categories
$builder
->add('categories', CollectionType::class, [
'entry_type' => ChoiceType::class,
'entry_options' => [
'choices' => $categories,
'choice_label' => function (Category $category = null) {
return null !== $category ? str_repeat('--', $category->getLevel()).' '.$category->getTitle() : '';
},
'choice_value' => function ($category = null) {
return $category instanceof Category ? $category->getId() : '';
},
'label' => false,
'placeholder' => '- Находится в -',
],
])
;
}
In both cases, no input fields would render unless your emails data array already contained some emails.
$product->getCategories()
пустой массив, то и поля выбора разделов не выводятся. Я так думаю, причина в этом.