-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce AsFilter attribute to define filter type and form type #348
base: 1.14
Are you sure you want to change the base?
Conversation
bfb5387
to
4b58c75
Compare
cd7c39a
to
215bc11
Compare
tests/Application/src/Grid/Builder/AttributeNationalityFilter.php
Outdated
Show resolved
Hide resolved
f6641a8
to
12a8575
Compare
c62a533
to
f63f29a
Compare
f63f29a
to
50b13cc
Compare
src/Bundle/DependencyInjection/Compiler/RegisterFiltersPass.php
Outdated
Show resolved
Hide resolved
50b13cc
to
81ae79d
Compare
src/Bundle/DependencyInjection/Compiler/RegisterFiltersPass.php
Outdated
Show resolved
Hide resolved
@vasilvestre you have two commits with "-" as commit message |
9edf05d
to
52e0442
Compare
ccb9197
to
a106327
Compare
1c49e46
to
f500a89
Compare
@@ -31,6 +32,11 @@ | |||
null, | |||
['author.nationality'], | |||
)) | |||
->addFilter(AttributeNationalityFilter::create( | |||
AttributeNationalityFilter::class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to be incorrect, or at least misleading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ? We can use FQCN as name and also call the create method of the filter.
@@ -31,6 +32,11 @@ | |||
null, | |||
['author.nationality'], | |||
)) | |||
->addFilter(AttributeNationalityFilter::create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it tested? Does it override nationality filter and is covered by this test:
SyliusGridBundle/src/Bundle/Tests/Functional/GridUiTest.php
Lines 235 to 245 in f500a89
public function it_includes_all_rows_even_when_sorting_by_a_nullable_path(): void | |
{ | |
$this->client->request('GET', '/authors/'); | |
$totalItemsCountBeforeSorting = count($this->getAuthorNamesFromResponse()); | |
$this->client->request('GET', '/authors/?sorting[nationality]=desc'); | |
$totalItemsCountAfterSorting = count($this->getAuthorNamesFromResponse()); | |
$this->assertSame($totalItemsCountBeforeSorting, $totalItemsCountAfterSorting); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's covered in https://github.com/Sylius/SyliusGridBundle/blob/f500a89f5ea35fd675012c30e55d0def0a751cc3/tests/Application/src/Filter/AttributeNationalityFilter.php and https://github.com/Sylius/SyliusGridBundle/blob/f500a89f5ea35fd675012c30e55d0def0a751cc3/tests/Application/src/Grid/Builder/AttributeNationalityFilter.php
This PR introduces a new attribute,
AsFilter
, to provide a more concise and structured way of defining filter types and form types for grid filters.Previously, filter types and form types were defined two methods inherited from
ConfigurableFilterInterface
.By using the
AsFilter
attribute, developers can now explicitly declare the type and form type of a filter directly above the class definition. This approach improves code readability, reduces reliance on tag attributes, and enhances maintainability.Steps:
Example usage:
The
RegisterFiltersPass
compiler pass has been updated to check for theAsFilter
attribute and ignore duplicate filter configuration.Tests are provided in the PR, documentation too.
A new behaviour is that type is now optional as the FQCN is now used by default. Which means you can reference it directly in PHP or YAML .
Future considerations:
In a future PR, we can consider deprecating the
ConfigurableFilterInterface
as it becomes redundant by introducing theAsFilter
attribute. This will further simplify the process of creating grid filters and improve consistency.