Closed JustDylan23 closed 3 years ago
It can't retrieve the parent field description for some reason, which results in a 500 error.
I found out that only the field description of the fields that were initially on the admin are avaiable to the extension
Which is supposed to call https://github.com/sonata-project/SonataAdminBundle/blob/23df35c1b6b943e290d7f5fef185f32ed81a59ac/src/Form/FormMapper.php#L158
You could try to debug these calls to see which one is not made.
public function add($name, ?string $type = null, array $options = [], array $fieldDescripti
{
if ($name === 'owner') throw new \Error('owner');
I have confirmed that the owner field is in fact not being added and also confirmed in the foreach that the extension is in fact being iterated through
public function configureFormFields(FormMapper $formMapper): void
{
if (!$this->security->isGranted('ROLE_SUPER_ADMIN')) {
throw new \Error('insufficient permissions');
return;
}
$isNewEntity = $formMapper->getAdmin()->getSubject()->getId() === null;
if ($isNewEntity) {
throw new \Error('new entity');
}
if ($isNewEntity || $formMapper->getAdmin()->hasParentFieldDescription()) {
throw new \Error('no parent description');
return;
}
$formMapper
->tab('Metadata')
->with('Source')
->add('owner', ModelAutocompleteType::class, [
'property' => 'username',
])
->end()
->end()
;
}
I did some debugging and apparently the variable named $isNewEntity is set to true
, this would indicate that for some reason it is not able to retrieve the subject.
I replaced the getSubject check with $formMapper->getAdmin()->isCurrentRoute('create')
now it does what it needs to do.
I am currently using the Alpha 2 version but this issue was present long before that.
The autocompletion works fine as long as I use it in an admin directly. You can easily reproduce this by creating a class that extends AbstractAdminExtension and simply adding a field of the type ModelAutocompleteType:class to the configureFormFields method like this: