Skip to content

Commit

Permalink
EntityFilterType introduce "choice_label" option
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Apr 3, 2023
1 parent db9def4 commit aa4159c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Bridge/Doctrine/Orm/Filter/Type/EntityFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public function apply(ProxyQueryInterface $query, FilterData $data, FilterInterf

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('field_type', EntityFormType::class);
$resolver->setDefaults([
'field_type' => EntityFormType::class,
'choice_label' => null,
]);

$resolver->setDefault('operator_options', function (OptionsResolver $resolver) {
$resolver->setDefaults([
Expand All @@ -55,12 +58,10 @@ public function configureOptions(OptionsResolver $resolver): void
});

$resolver->setDefault('active_filter_formatter', function (FilterData $data, FilterInterface $filter, array $options): mixed {
$propertyAccessor = PropertyAccess::createPropertyAccessor();

$choiceLabel = $options['field_options']['choice_label'];
$choiceLabel = $options['choice_label'];

if (is_string($choiceLabel)) {
return $propertyAccessor->getValue($data->getValue(), $choiceLabel);
return (PropertyAccess::createPropertyAccessor())->getValue($data->getValue(), $choiceLabel);
}

if (is_callable($choiceLabel)) {
Expand Down

0 comments on commit aa4159c

Please sign in to comment.