From 1900842d372fa8d8636da4d4de2c4dcc0f0efefb Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Wed, 1 Aug 2012 17:15:31 +1000 Subject: [PATCH] Make the list used for autocomplete search results settable. This is useful if you want to limit the autocomplete results to a subset of all available objects. --- .../GridFieldAddExistingAutocompleter.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/forms/gridfield/GridFieldAddExistingAutocompleter.php b/forms/gridfield/GridFieldAddExistingAutocompleter.php index 06b2bca68..3df3af4d6 100644 --- a/forms/gridfield/GridFieldAddExistingAutocompleter.php +++ b/forms/gridfield/GridFieldAddExistingAutocompleter.php @@ -21,6 +21,11 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF */ protected $targetFragment; + /** + * @var SS_List + */ + protected $searchList; + /** * Which columns that should be used for doing a "StartsWith" search. * If multiple fields are provided, the filtering is performed non-exclusive. @@ -167,8 +172,12 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF * @param SS_HTTPRequest $request */ public function doSearch($gridField, $request) { - $dataClass = $gridField->getList()->dataClass(); - $allList = DataList::create($dataClass); + if($this->searchList) { + $allList = $this->searchList; + } else { + $allList = DataList::create($gridField->getList()->dataClass()); + } + $filters = array(); $stmts = array(); @@ -209,6 +218,16 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF return $this->resultsFormat; } + /** + * Sets the base list instance which will be used for the autocomplete + * search. + * + * @param SS_List $list + */ + public function setSearchList(SS_List $list) { + $this->searchList = $list; + } + /** * @param Array */