FIX support search filter instances (#9991)

and also fully qualified class names
This commit is contained in:
Thomas Portelange 2022-01-21 04:33:51 +01:00 committed by GitHub
parent d1d1e9f58e
commit 0cfd98d87a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@ use SilverStripe\ORM\DataList;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use LogicException;
use SilverStripe\ORM\Filters\SearchFilter;
/**
* This class is is responsible for adding objects to another object's has_many
@ -349,7 +350,18 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
if (!$customSearchableFields || array_search($name, $customSearchableFields)) {
$filter = 'StartsWith';
} else {
$filter = preg_replace('/Filter$/', '', $spec['filter']);
$filterName = $spec['filter'];
// It can be an instance
if ($filterName instanceof SearchFilter) {
$filterName = get_class($filterName);
}
// It can be a fully qualified class name
if (strpos($filterName, '\\') !== false) {
$filterNameParts = explode("\\", $filterName);
// We expect an alias matching the class name without namespace, see #coresearchaliases
$filterName = array_pop($filterNameParts);
}
$filter = preg_replace('/Filter$/', '', $filterName);
}
$fields[] = "{$name}:{$filter}";
} else {