Skip to content

Commit

Permalink
Passing EntityDto to AssociationField::OPTION_QUERY_BUILDER_CALLABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoJunior authored Mar 1, 2024
1 parent 6f72112 commit 79c7a91
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Field/Configurator/AssociationConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c

$field->setFormTypeOption('attr.data-ea-autocomplete-endpoint-url', $autocompleteEndpointUrl);
} else {
$field->setFormTypeOptionIfNotSet('query_builder', static function (EntityRepository $repository) use ($field) {
// Passing the entityDto to the callback - Sometimes it can be usefull to filter data depending on the entity data
$field->setFormTypeOptionIfNotSet('query_builder', static function (EntityRepository $repository) use ($field, $entityDto) {
// TODO: should this use `createIndexQueryBuilder` instead, so we get the default ordering etc.?
// it would then be identical to the one used in autocomplete action, but it is a bit complex getting it in here
$queryBuilder = $repository->createQueryBuilder('entity');
if (null !== $queryBuilderCallable = $field->getCustomOption(AssociationField::OPTION_QUERY_BUILDER_CALLABLE)) {
$queryBuilderCallable($queryBuilder);
$queryBuilderCallable($queryBuilder, $entityDto);
}

return $queryBuilder;
Expand Down

0 comments on commit 79c7a91

Please sign in to comment.