Skip to content
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

FIX Respect searchable_fields #10733

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Mar 22, 2023

Comment on lines 261 to 262
$searchableFields = Config::inst()->get($modelClass, 'searchable_fields');
if (!empty($searchableFields)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make sure here that searchable_fields is an array if set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have changed to use $modelClass::singleton()->searchableFields() which returns an array

if ($title && $list->canFilterBy($columnField)) {
return true;
$modelClass = $gridField->getModelClass();
$searchableFields = Config::inst()->get($modelClass, 'searchable_fields');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searchable fields should be fetched by calling searchableFields() on a singleton, i.e. $modelClass::singleton()->searchableFields()
See SearchContext and GridFieldAddExistingAutocompleter as examples of where this is already done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 264 to 268
foreach ($searchableFields as $searchableField) {
if ($list->canFilterBy($searchableField)) {
return true;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canFilterBy() is fine for summary_fields() - but we can declare searchable_fields that aren't traditionally filterable here, and then tell SearchContext how to search using those fields. If a field is in searchable fields that isn't in summary fields, we should just assume it's filterable and let SearchContext sort it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote the method

@emteknetnz emteknetnz force-pushed the pulls/4.13/searchable branch from 66a2bb5 to 0f40cc3 Compare March 22, 2023 21:57
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants