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;