Changing the default filter criteria to "Is equal to" - version 3.x #8184
Unanswered
ThisuraThejith
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Try using The default filter values are directly merged with the passed query. There is no further processing of the provided keys, as far, as i know of. If your stil want to use the protected function configureDefaultFilterValues(array &$filterValues)
{
$availableFilterFields = [
'id',
'message',
'user.id',
'user.artist_name',
'song.id',
'song.name',
'article.title',
];
foreach ($availableFilterFields as $fieldName) {
$filterValues[str_replace('.', '__', $fieldName)] = [
"type" => ChoiceType::TYPE_EQUAL
];
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Good day,
I'm working with Sonata Admin Panel 3.x and currently I'm working on changing the default filter matching criteria from "contains" to "is equal to" for some filter fields to filter certain entities. Refer the below screen shot to have a more clear idea.
I'll take one entity called "Comments" to explain my problem. The following are the filter fields that I have to filter comments.
As I need to always set the value to "is equal to" in the first drop down after clicking on "Advanced filters", I've overridden the "configureDefaultFilterValues" in the "CommentAdmin" file as follows.
When it comes to a filter field which is a direct property of the Comment entity (for example "message" in this case), this works and "is equal to" is selected as the default filter criteria as follows.
But the problem is when it comes to a filter field which is associated to the Comment entity through another entity like User Artist Name, which will be accessed in the CommentAdmin file as user.artist_name, which is included in the $availableFilterFields array in the above method, this doesn't work and "is equal to" is not selected as the default filter criteria as in the following screenshot.
Is there a way to resolve this? And add to that I'd appreciate if anyone can suggest a way to centrally change this default filter criteria to "is equal to" in every place, as that is the filter criteria that is mostly used by our system admins and it will be very convenient to have it already selected.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions