formssymfonytwigformbuilder

Symfony form generate not expected placeholder element


Usually, there should be two outputs both filled with taxonomy ids - somehow there is a "placeholder" element which causes errors. I don't really understand where it comes from, any ideas?

I thought the best idea is to show it within a screenshot (and additional, a part of it as code). The output is with twig's dump() function.

Generated symfony form element id's within dump() (3 form elements, 2 expected):

"id" => "Filter_filter_1462_boolcollectionradiomodell_placeholder"
"id" => "Filter_filter_1462_boolcollectionradiomodell_8368"
"id" => "Filter_filter_1462_boolcollectionradiomodell_33696" 

Here the screenshots with the ids and some additional information like the empty value from the symfony form element: enter image description here

The value is empty, the other ones (the expected ones) are filled with taxonomy ids.

Here is the symfony form part:

$builder->add(
    'filter_' . $filter->getId() . '_boolcollectionradio',
    EntityType::class,
    array(
        'class' => AutoTaxonomie::class,
        'choices' => $choices,
        'expanded' => true,
        'multiple' => false,
        'required' => false,
        'label' => ('detail' == $this->entry) ? $tmp : false,
        'attr' => array('data-taxid' => $filter->getId(), 'class' => 'form-group'),
        'choice_label' => function (AutoTaxonomie $taxonomie) {
            $view_data = array(
                'title' => $taxonomie->getTitle(),
                'beschreibung' => $taxonomie->getDescription(),
            );

            return json_encode($view_data);
        },
    )
);

symfony: 3.4 twig: 2.5

Any advice is highly appreciated, have a nice one!


Solution

  • Displaying a placeholder element for the EntityTypeField is the default, as documented. Try setting it to false to prevent it from appearing:

    $builder->add('filter_', EntityType::class, array(
        'placeholder' => false,
    ));