您正在使用 ->hideOnForm,它会删除表单中的字段,因此不会发送任何关于person的内容。
有多种方法可以做你想做的事,包括类似的答案,比如你的用户有一个隐藏的选择,但我不认为这是一个好的解决方案。
您是否考虑过使用 Event ?
在您的情况下,您可以使用 Doctrine 事件或 EasyAdmin 事件进行监听。
Symfony 事件
<?php
namespace App\EventSubscriber;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
//... other imports
class EasyAdminSubscriber implements EventSubscriberInterface
{
private $tokenStorage
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage
}
public static function getSubscribedEvents()
{
return [BeforeEntityUpdatedEvent => ['beforeEntityUpdatedEvent'], ];
}
public function beforeEntityUpdatedEvent(BeforeEntityUpdatedEvent $event)
{
$entity = $event->getEntityInstance();
if ($entity instanceof YourEntityYouWantToListenTo) {
$entity->setPerson($this->tokenStorage->getToken()->getUser());
}
}