From 79c7a91794465cfed68a817eee2cdd9701d6e7ed Mon Sep 17 00:00:00 2001 From: Bruno Desprez Date: Fri, 1 Mar 2024 12:54:32 +0100 Subject: [PATCH] Passing EntityDto to AssociationField::OPTION_QUERY_BUILDER_CALLABLE --- src/Field/Configurator/AssociationConfigurator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Field/Configurator/AssociationConfigurator.php b/src/Field/Configurator/AssociationConfigurator.php index e5f8702038..81e494b56f 100644 --- a/src/Field/Configurator/AssociationConfigurator.php +++ b/src/Field/Configurator/AssociationConfigurator.php @@ -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;