Symfony 4嵌套集合by_reference无法正常工作

I've an issue with a complex form

It's a templater wich describes a film (scenes, elements, conditions, ...)


It look like this : enter image description here

Inside the elements collection I have a nested collection options :

enter image description here

My weird issue is : The following setter when I submit the whole form send an array instead of a collection. Thing is on the the update form, when submitting, the collection is already set.

/**
 * @param Collection $options
 * @return Element
 */
public function setOptions($options): Element
{
    if (!$options instanceof Collection) {
        var_dump($options);
        var_dump('fall here');exit;
        $this->options = new ArrayCollection($options);
    } else {
        var_dump($options);
        $this->options = $options;
    }


    return $this;
}

Weirder thing :

/**
 * @param \App\Domain\Toto\Template\Entity\ElementOptions $option
 * @return $this
 */
public function addElementOptions(ElementOptions $option): self
{
    var_dump('Element::addElementOptions'); exit;
    $option->setElement($this);
    $this->options->add($option);

    return $this;
}

/**
 * @param ElementOptions $option
 */
public function removeElementOptions(ElementOptions $option)
{
    $this->options->removeElement($option);
}

Those are never called.

My suggestion is the by_reference option from the form builder is not working in a nested collection.

But I'm really overwhelmed here, I would appreciate a suggestion of what I possibly missed.

Here the code relevant to this nested collection :

Element.orm (An element has one or many elementOption)

<one-to-many field="options" target-entity="App\Domain\Toto\Template\Entity\ElementOptions" mapped-by="element" fetch="LAZY">
    <cascade>
    <cascade-all/>
    </cascade>
</one-to-many>

ElementOption entity

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Domain\Toto\Template\Entity\ElementOptions" table="tpl_element_options">
        <id name="id" type="integer" column="id">
            <generator strategy="IDENTITY"/>
        </id>
        <many-to-one field="element" target-entity="App\Domain\Toto\Template\Entity\Element" inversed-by="options" fetch="LAZY">
            <join-columns>
                <join-column name="element_id" referenced-column-name="id" on-delete="CASCADE"/>
            </join-columns>
        </many-to-one>
        <many-to-one field="type" target-entity="App\Domain\Toto\Template\Entity\Type">
            <join-columns>
                <join-column name="type_id" referenced-column-name="id" on-delete="CASCADE" nullable="1"/>
            </join-columns>
        </many-to-one>
        <field name="value" type="string" column="value" length="150" precision="0" scale="0" nullable="false">
            <options>
                <option name="comment">This column stores the value for the option</option>
            </options>
        </field>
    </entity>
</doctrine-mapping>

Element Form builder, declaration of the elementOption collection

        ->add('options', CollectionType::class,
            [
                'entry_type'     => ElementOptionsForm::class,
                'by_reference'   => false,
                'allow_add'      => true,
                'allow_delete'   => true,
                'prototype'      => true,
                'prototype_name' => '__ELEMENT_OPTION__',
                'attr'           => [
                    'class' => 'table scene-elements-option',
                ],
                'label' => 'templates.new.form.scene.element.option.title'
            ]
        );

In the controller, my form is populated with post values as follow :

    $form = $this->formFactory->create($type, $data, $options);
    $form->handleRequest($this->requestStack->getCurrentRequest());

    return $form;