Add request origin for EntityFilter autocomplete() requests
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Compare the EntityFilter autocomplete URL construction with the AssociationField's existing autocomplete context, then trace the request into the target CRUD controller's createIndexQueryBuilder(). Confirm that EntityFilter autocomplete requests carry the needed origin context and that the query-builder use case works without the page crashing.
Written by the indexing model from the issue text.
Description
Short description of what this feature will allow to do:
Using the EntityFilter with autocomplete() adds additional context to the AJAX requests, so related controllers can check for this context inside the createIndexQueryBuilder() method. Similar, what the AssociationField is already doing.
Right now, if you want to limit the list of selectable products, you need to add the value_type_options.query_builder callable to the EntityFilter form type options. But this only works for as long as you're not using the autocomplete() feature. As soon as you add autocomplete, the page crashes, because the option query_builder does not exist.
Example of how to use this feature
I added a custom filter + custom filter configurator which is basically a copy of the \EasyCorp\Bundle\EasyAdminBundle\Filter\Configurator\EntityConfigurator. I added the following context:
$autocompleteEndpointUrl = $this->adminUrlGenerator
->unsetAll()
->set('page', 1)
->setController($targetCrudControllerFqcn)
->setAction('autocomplete')
->set(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT, [
'propertyName' => $propertyName,
'originatingPage' => $context->getCrud()?->getCurrentAction() ?? throw new \LogicException('The current action is not defined.'),
+ 'filterSource' => 'whateverProperty', // Needs to be set from filterDto automatically maybe?
+ 'originatingCrudControllerFqcn' => $context->getRequest()->attributes->get(EA::CRUD_CONTROLLER_FQCN),
])
->generateUrl();
And inside the createIndexQueryBuilder() method of my related crud controller, I am doing:
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
$queryBuilder = parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
$autocompleteContext = $this->getContext()?->getRequest()->query->all(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);
if (
($autocompleteContext['filterSource'] ?? null) === 'whateverProperty'
&& ($autocompleteContext['originatingCrudControllerFqcn'] ?? null) === MyCrudController::class
) {
$queryBuilder->innerJoin('entity.relatedEntity', 'relatedEntity');
}
return $queryBuilder;
}
- Dominant language
- PHP
- Stars
- 4.3k
- Forks
- 1.1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 52
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EasyCorp/EasyAdminBundle
-
bug design
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
EasyCorp/EasyAdminBundle#7958 ·
Maintainers usually reply within 2 days
-
design feature
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
EasyCorp/EasyAdminBundle#7930 ·
Maintainers usually reply within 2 days
-
design
Difficulty 2/5 Under an hour Newbie friendliness 88/100
EasyCorp/EasyAdminBundle#7879 ·
Maintainers usually reply within 2 days
-
design
Difficulty 1/5 Under an hour Newbie friendliness 90/100
EasyCorp/EasyAdminBundle#7875 ·
Maintainers usually reply within 2 days
-
#[AdminRoute]: the requirements of an action silently replace the ones of the classPossibly taken @anthonyhacart claimed this 1 day ago. Openfeature
Difficulty 3/5 Half a day Newbie friendliness 30/100
EasyCorp/EasyAdminBundle#7956 ·
Maintainers usually reply within 2 days
All issues in EasyCorp/EasyAdminBundle
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
area/import type/enhancement when/later
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
parime/glpi-iso27001-management#1165 ·
Maintainers usually reply within 1 day
-
15.0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opnsense/plugins#5976 · 1 comment ·
Maintainers usually reply within 1 day