Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Add filter_shared_name option to override join name (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
danut007ro authored Aug 20, 2021
1 parent e8a6bea commit e54df97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Filter/FilterBuilderUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function addFilters(FormInterface $form, QueryInterface $filterQuery,

// this means we have a relation
if ($child->getConfig()->hasAttribute('add_shared')) {
$join = trim($alias . '.' . $child->getName(), '.');
$join = $child->getConfig()->getAttribute('filter_shared_name') ?? trim($alias . '.' . $child->getName(), '.');

$addSharedClosure = $child->getConfig()->getAttribute('add_shared');

Expand All @@ -150,7 +150,7 @@ protected function addFilters(FormInterface $form, QueryInterface $filterQuery,

// Doctrine2 embedded object case
} elseif ($formType instanceof EmbeddedFilterTypeInterface) {
$this->addFilters($child, $filterQuery, $alias . '.' . $child->getName());
$this->addFilters($child, $filterQuery, $child->getConfig()->getAttribute('filter_field_name') ?? ($alias . '.' . $child->getName()));

// default case
} else {
Expand Down
5 changes: 5 additions & 0 deletions Filter/Form/FilterTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if (null !== $options['filter_field_name']) {
$builder->setAttribute('filter_field_name', $options['filter_field_name']);
}

if (null !== $options['filter_shared_name']) {
$builder->setAttribute('filter_shared_name', $options['filter_shared_name']);
}
}

/**
Expand All @@ -42,6 +46,7 @@ public function configureOptions(OptionsResolver $resolver)
'data_extraction_method' => 'default',
'filter_condition_builder' => null,
'filter_field_name' => null,
'filter_shared_name' => null,
));
}

Expand Down
4 changes: 4 additions & 0 deletions Resources/doc/filtertypeextension.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ See [4.iii section](working-with-the-bundle.md#iii-customize-condition-operator)

This option is used to define the field name on which the condition is applied.

##### The `filter_shared_name` option:

This option is used to define the shared join name on which the condition is applied.

***

Next: [7. Working with other bundles](working-with-other-bundles.md)

0 comments on commit e54df97

Please sign in to comment.