Source of file AddExistingPicker.php
Size: 3,846 Bytes - Last Modified: 2021-12-23T10:04:57+00:00
/var/www/docs.ssmods.com/process/src/code/Buttons/AddExistingPicker.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 | <?php namespace Milkyway\SS\GridFieldUtils; /** * Milkyway Multimedia * AddExistingPicker.php * * @package milkyway-multimedia/ss-gridfield-utils * @author Mellisa Hankins <mell@milkywaymultimedia.com.au> */ if (!class_exists('GridFieldAddExistingSearchButton')) { return; } use GridFieldAddExistingSearchButton as AddExistingSearchButton; use GridFieldExtensions; use ArrayData; use Milkyway\SS\GridFieldUtils\Controllers\AddExistingPicker as Controller; class AddExistingPicker extends AddExistingSearchButton { protected $searchHandlerFactory; protected $addHandler; protected $undoHandler; protected $urlSegment; public $async = true; /** * Set a search handler factory, which can create a custom RequestHandler * to be used for searching * * @param callable $searchHandlerFactory * @return self $this */ public function setSearchHandlerFactory($searchHandlerFactory) { $this->searchHandlerFactory = $searchHandlerFactory; return $this; } /** * @return callable|null */ public function getSearchHandlerFactory() { return $this->searchHandlerFactory; } /** * Sets a custom handler for when the add action is called * * @param callable $addHandler * @return self $this */ public function setAddHandler($addHandler) { $this->addHandler = $addHandler; return $this; } /** * @return callable|null */ public function getAddHandler() { return $this->addHandler; } /** * Sets a custom handler for undoing the add action * * @param callable $undoHandler * @return self $this */ public function setUndoHandler($undoHandler) { $this->undoHandler = $undoHandler; return $this; } /** * @return callable|null */ public function getUndoHandler() { return $this->undoHandler; } /** * @return string */ public function getUrlSegment() { return $this->urlSegment; } /** * @param string $urlSegment */ public function setUrlSegment($urlSegment = '') { $this->urlSegment = $urlSegment; return $this; } /** * Enable the async picker, when an item is clicked in the list * it is automatically added to the list, with an undo option. * * @param bool $async * @return self $this */ public function async($async = true) { $this->async = $async; return $this; } /** * @return bool */ public function isAsync() { return $this->async; } public function handleSearch($grid, $request) { if ($this->searchHandlerFactory) { return call_user_func($this->searchHandlerFactory, $grid, $this, $request); } else { return Controller::create( $grid, $this, $request ); } } public function getHTMLFragments($grid) { GridFieldExtensions::include_requirements(); Utilities::include_requirements(); $data = ArrayData::create([ 'Title' => $this->getTitle(), 'Link' => $grid->Link($this->urlSegment ?: 'add-existing-search'), ]); if ($this->async) { $grid->addExtraClass('ss-gridfield-add-existing-picker_async'); } return [ $this->fragment => $data->renderWith([ 'GridField_AddExistingPicker', 'GridFieldAddExistingSearchButton', ]), ]; } public function getURLHandlers($grid) { return [ $this->urlSegment ?: 'add-existing-search' => 'handleSearch', ]; } } |