Fix autocomplete context crud controller for embedded forms#6788
Open
zorn-v wants to merge 1 commit intoEasyCorp:4.xfrom
Open
Fix autocomplete context crud controller for embedded forms#6788zorn-v wants to merge 1 commit intoEasyCorp:4.xfrom
zorn-v wants to merge 1 commit intoEasyCorp:4.xfrom
Conversation
Contributor
Author
|
As workaround for now # config/services.yaml
services:
#...
App\EasyAdmin\Field\Configurator\AssociationConfigurator:
tags:
- { name: 'ea.field_configurator', priority: -1 }<?php
namespace App\EasyAdmin\Field\Configurator;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
/** fix EA autocomplete bug in embedded forms */
final class AssociationConfigurator implements FieldConfiguratorInterface
{
public function supports(FieldDto $field, EntityDto $entityDto): bool
{
return AssociationField::class === $field->getFieldFqcn();
}
public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
{
if (true === $field->getCustomOption(AssociationField::OPTION_AUTOCOMPLETE)) {
$endpointUrl = $field->getFormTypeOption('attr.data-ea-autocomplete-endpoint-url');
[$path, $query] = explode('?', $endpointUrl);
parse_str($query, $data);
$data['autocompleteContext'][EA::CRUD_CONTROLLER_FQCN] = $context->getCrudControllers()->findCrudFqcnByEntityFqcn($entityDto->getFqcn());
$endpointUrl = $path.'?'.http_build_query($data);
$field->setFormTypeOption('attr.data-ea-autocomplete-endpoint-url', $endpointUrl);
}
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you have embedded form with association autocomplete field and have defined
setQueryBuilderthere, then it will not applied ascrudControllerFqcncomes from request now.But request has info about parent controller, not embedded. So configurator can not find field with configured query builder and it does not applied.