diff --git a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php index afec2e03c..c652fee56 100644 --- a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php +++ b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php @@ -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 {