Allow setting a custom search items list

Closes #13. Closes #14.
This commit is contained in:
Andrew Short 2013-03-28 20:43:17 +11:00
parent 0584ad3c49
commit ff710c9b92
2 changed files with 26 additions and 2 deletions

View File

@ -9,6 +9,7 @@ class GridFieldAddExistingSearchButton implements
protected $title; protected $title;
protected $fragment; protected $fragment;
protected $searchList;
/** /**
* @param string $fragment * @param string $fragment
@ -46,6 +47,22 @@ class GridFieldAddExistingSearchButton implements
$this->fragment = $fragment; $this->fragment = $fragment;
} }
/**
* Sets a custom list to use to provide the searchable items.
*
* @param SS_List $list
*/
public function setSearchList(SS_List $list) {
$this->searchList = $list;
}
/**
* @return SS_List|null
*/
public function getSearchList() {
return $this->searchList;
}
public function getHTMLFragments($grid) { public function getHTMLFragments($grid) {
GridFieldExtensions::include_requirements(); GridFieldExtensions::include_requirements();

View File

@ -76,7 +76,7 @@ class GridFieldAddExistingSearchHandler extends RequestHandler {
} }
public function doSearch($data, $form) { public function doSearch($data, $form) {
$list = $this->context->getResults($data); $list = $this->context->getQuery($data, false, false, $this->getSearchList());
$list = $list->subtract($this->grid->getList()); $list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request); $list = new PaginatedList($list, $this->request);
@ -88,7 +88,7 @@ class GridFieldAddExistingSearchHandler extends RequestHandler {
} }
public function Items() { public function Items() {
$list = DataList::create($this->grid->getList()->dataClass()); $list = $this->getSearchList();
$list = $list->subtract($this->grid->getList()); $list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request); $list = new PaginatedList($list, $this->request);
@ -99,4 +99,11 @@ class GridFieldAddExistingSearchHandler extends RequestHandler {
return Controller::join_links($this->grid->Link(), 'add-existing-search', $action); return Controller::join_links($this->grid->Link(), 'add-existing-search', $action);
} }
/**
* @return DataList
*/
protected function getSearchList() {
return $this->button->getSearchList() ?: DataList::create($this->grid->getList()->dataClass());
}
} }