I myself have been searching for a solution and waiting for a long time and we are not alone. It appears EasyCorp/EasyAdminBundle gave up on this.
While this may not be the answer you're looking for, so far the only solution I've found is to read the request in your custom form type; same as you would in the controller. This necessitates that the data is in the request URI somehow otherwise it won't work.
Example URI: /path/to/action/[ID] or /path/to/action/99 where '99' is the ID of the entity you're looking for.
use App\Repository\SomeRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class AttrType extends AbstractType
{
private ?Request $request = null;
private SomeRepository $repository;
public function __construct(RequestStack $requestStack, SomeRepository $repository)
{
$this->repository = $repository;
if ($req = $requestStack->getCurrentRequest()) {
$this->request = $req;
}
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if ($this->request && $id = (int) $this->request->get('id')) {
$parentFormData = $this->repository->find($id);
}
}
}
This of course requires a second lookup of the same data so it's far from elegant but it has worked in some situations for me and allowed me to keep my parent form type clean.
Hope it helps.
EDIT:
You can get the parent form data in buildView()
as well but that usually never sufficed for me, hence the above solution. For anyone who is unaware of this, here it is:
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
class AttrType extends AbstractType
{
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$parentData = $form->getParent()->getData();
}
}