-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add option to modify query of AssociationField (with autocomplete) #3551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| return $this->getController(DashboardControllerInterface::class, $dashboardControllerFqcn, 'index', $request); | ||
| } | ||
|
|
||
| public function getCrudController(?string $crudControllerFqcn, ?string $crudAction, Request $request): ?CrudControllerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/EasyCorp/EasyAdminBundle/pull/3550/files#r453887481 for discussion.
| $field->setFormTypeOption('attr.data-ea-autocomplete-endpoint-url', $autocompleteEndpointUrl); | ||
| } else { | ||
| $field->setFormTypeOption('query_builder', static function(EntityRepository $repository) use($field) { | ||
| // TODO: should this use `createIndexQueryBuilder` instead, so we get the default ordering etc.? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure about this one yet. We could also work around this, by using Crud::getDefaultSort and applying the conditions directly, but I'm not convinced that that would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, this code generates an error (see #4229) if the $field type doesn't have a "query_builder" option. Which, in practice, if it doesn't inherit of EntityType.
|
Could that solve #3490? |
This PR was merged into the 3.0.x-dev branch. Discussion ---------- Extract ControllerFactory service This is a pre-requisite for EasyCorp#3476 (MR EasyCorp#3551) and EasyCorp#3352 (see EasyCorp#3543 (comment) for details). Also deduplicated a bit of the shared logic between CrudController and DashboardController creation. Commits ------- ed63197 Extract ControllerFactory service
…tocomplete) (lukasluecke) This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- Add option to modify query of AssociationField (with autocomplete) Resolves #3476. Depends on #3550. Works the same for "default" and autocomplete fields. ```php AssociationField::new('property') ->autocomplete() // optional ->modifyQuery(fn(QueryBuilder $queryBuilder) => $queryBuilder ->where('entity.id > 20') ->orderBy('entity.field', 'DESC') ); ``` Commits ------- 4716e81 Add option to modify query of AssociationField (with autocomplete)
|
Lukas, thanks a lot for contributing this feature. I did some very minor tweaks and renames while merging, but I left most of your contribution intact. Thanks! |
…s (javiereguiluz) This PR was merged into the 3.0.x-dev branch. Discussion ---------- Don't override the query_builder form option in associations This is related to #3551, which we merged yesterday. One of my apps started failing because it used a custom `query_builder` form option. Commits ------- 3cc9c8a Don't override the query_builder form option in associations
…reguiluz) This PR was merged into the 3.0.x-dev branch. Discussion ---------- Fixed the autocomplete feature of association fields This is related to #3551. Autocomplete stopped working in one of my apps. The reason is that the autocomplete field is not shown on `index/detail` but only on `edit/new` ... so let's not assume that the page where the field is defined is always `index`. Commits ------- de42aa4 Fixed the autocomplete feature of association fields
…syCorp#3551 See EasyCorp#4229 : If the AssociationType is used with a FormType that doesn't have a query_builder option, Symfony will complain. As for now, it is just a hack, I suppose there may be a better way to do that. That's why I voluntarily kept the FQCN during the discussion.
Resolves #3476. Depends on #3550.
Works the same for "default" and autocomplete fields.