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.
This commit is contained in:
Andrew Short 2012-08-01 17:15:31 +10:00 committed by Will Rossiter
parent ec25afc61e
commit 1900842d37

View File

@ -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
*/