Symfony. После отправки формы не содержит ни одного элемента из ArrayCollection CollectionType в форме

После отправки формы,форма не содержит ни одного элемента, в итоговом варианте на странице только label-Invaited и кнопка, а самого элемента input нет.Что я упустил, или что я делаю не так?

Сущность User


<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
 */
class User
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Invaited")
     */
    private $invaited;

    public function __construct()
    {
        $this->invaited = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return Collection|Invaited[]
     */
    public function getInvaited(): Collection
    {
        return $this->invaited;
    }

    public function addInvaited(Invaited $invaited): self
    {
        if (!$this->invaited->contains($invaited)) {
            $this->invaited[] = $invaited;
        }

        return $this;
    }

    public function removeInvaited(Invaited $invaited): self
    {
        if ($this->invaited->contains($invaited)) {
            $this->invaited->removeElement($invaited);
        }

        return $this;
    }
}


Сущность Invaited


<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="App\Repository\InvaitedRepository")
 */
class Invaited
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Assert\NotBlank(message="Поле фамилия не должно быть пустым *")
     */
    private $invaited;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getInvaited(): ?string
    {
        return $this->invaited;
    }

    public function setInvaited(string $invaited): self
    {
        $this->invaited = $invaited;

        return $this;
    }
}

Форма сущности User

<?php


namespace App\Form;

use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TestForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('invaited', CollectionType::class, [
            'entry_type' => TwoForm::class,
        ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class'=>User::class
        ]);
    }


}

Форма сущности Invaited

<?php


namespace App\Form;


use App\Entity\Invaited;
use App\Entity\Organization;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TwoForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        //parent::buildForm($builder, $options); // TODO: Change the autogenerated stub
        $builder->add('invaited');
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class'=>Invaited::class
        ]);
    }
}

Главный контроллер

<?php

namespace App\Controller;

use App\Entity\Invaited;
use App\Entity\Organization;
use App\Entity\User;
use App\Form\TestForm;
use App\Form\TwoForm;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class MainController extends AbstractController
{
    /**
     * @Route("/main", name="main")
     */
    public function index(EntityManagerInterface $entityManager, UserRepository $userRepository, Request $request)
    {
        $user = new User();
        $form = $this->createForm(TestForm::class, $user);
        $form->handleRequest($request);
        return $this->render('main/index.html.twig', [
            'controller_name' => 'MainController',
            'form'=>$form->createView()
        ]);
    }
}

twig шаблон

{% extends 'base.html.twig' %}

{% block body %}

    {{ form_start(form)}}
    {{ form_widget(form) }}
    <button type="submit" class="button">Отправить</button>
    {{ form_end(form) }}
{% endblock %}

Ответы (0 шт):