Source of file PickerFieldAddExistingSearchHandler.php
Size: 2,010 Bytes - Last Modified: 2021-12-23T10:51:29+00:00
/var/www/docs.ssmods.com/process/src/code/PickerFieldAddExistingSearchHandler.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php namespace TheWebmen\PickerField\Controllers; use SilverStripe\ORM\PaginatedList; use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchHandler; use SilverStripe\ORM\DataList; class PickerFieldAddExistingSearchHandler extends GridFieldAddExistingSearchHandler { private static $allowed_actions = array( 'index', 'add', 'SearchForm' ); public function add($request) { // use native GridFieldAddExistingSearchHandler add() method when not has_one if(!$this->grid->isHaveOne()) { return parent::add($request); } if(!$id = $request->postVar('id')) { $this->httpError(400); } // appropriate handling of has_one relationships $childProperty = $this->grid->getName() . 'ID'; $this->grid->childObject->$childProperty = $id; $this->grid->childObject->write(); } public function doSearch($data, $form) { $list = $this->context->getQuery($data, false, false, $this->getSearchList()); $list = $this->applySearchFilters($list); $list = $list->subtract($this->grid->getList()); $list = new PaginatedList($list, $this->request); $data = $this->customise(array( 'SearchForm' => $form, 'Items' => $list )); return $data->index(); } public function Items() { $list = $this->getSearchList(); $list = $this->applySearchFilters($list); $list = $list->subtract($this->grid->getList()); $list = new PaginatedList($list, $this->request); return $list; } public function getSearchList() { $component = $this->grid->getConfig()->getComponentByType(PickerFieldAddExistingSearchButton::class); return $component->getSearchList() ?: DataList::create($this->grid->getList()->dataClass()); } public function applySearchFilters($list){ $component = $this->grid->getConfig()->getComponentByType(PickerFieldAddExistingSearchButton::class); if($filters = $component->getSearchFilters()) { $list = $list->filter($filters); } if($excludes = $component->getSearchExcludes()) { $list = $list->exclude($excludes); } return $list; } } |