Source of file Handler.php
Size: 5,813 Bytes - Last Modified: 2021-12-23T10:09:24+00:00
/var/www/docs.ssmods.com/process/src/src/BulkManager/BulkAction/Handler.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 | <?php namespace Colymba\BulkManager\BulkAction; use SilverStripe\Control\Controller; use SilverStripe\Control\RequestHandler; use SilverStripe\Forms\GridField\GridFieldDetailForm; use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; use SilverStripe\ORM\DataList; use SilverStripe\View\ArrayData; /** * Base class to extend for all custom bulk action handlers * Gives access to the GridField, Component and Controller * and implements useful functions like {@link getRecordIDList()} and {@link getRecords()}. * * @author colymba */ class Handler extends RequestHandler { /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name * * @var string */ private static $url_segment = null; /** * Related GridField instance. * * @var GridField */ protected $gridField; /** * GridFieldBulkManager instance. * * @var GridFieldBulkManager */ protected $component; /** * Front-end label for this handler's action * * @var string */ protected $label = 'Action'; /** * Front-end icon path for this handler's action. * * @var string */ protected $icon = ''; /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash * * @var string */ protected $buttonClasses = ''; /** * Whether this handler should be called via an XHR from the front-end * * @var boolean */ protected $xhr = true; /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. * * @var boolean */ protected $destructive = false; /** * @param GridField $gridField * @param GridField_URLHandler $component */ public function __construct($gridField = null, $component = null) { $this->gridField = $gridField; $this->component = $component; parent::__construct(); } /** * Return front-end configuration * * @return array */ public function getConfig() { $config = array( 'label' => $this->getI18nLabel(), 'icon' => $this->getIcon(), 'buttonClasses' => $this->getButtonClasses(), 'xhr' => $this->getXhr(), 'destructive' => $this->getDestructive() ); return $config; } /** * Set if hanlder performs destructive actions * * @param boolean destructive If true, a warning will be shown on the front-end * @return RequestHandler */ public function setDestructive($destructive) { $this->destructive = $destructive; return $this; } /** * True if the hanlder performs destructive actions * * @return boolean */ public function getDestructive() { return $this->destructive; } /** * Set if handler is called via XHR * * @param boolean xhr If true the handler will be called via an XHR from front-end * @return RequestHandler */ public function setXhr($xhr) { $this->xhr = $xhr; return $this; } /** * True if handler is called via XHR * * @return boolean */ public function getXhr() { return $this->xhr; } /** * Set front-end buttonClasses * * @return RequestHandler */ public function setButtonClasses($buttonClasses) { $this->buttonClasses = $buttonClasses; return $this; } /** * Return front-end buttonClasses * * @return string */ public function getButtonClasses() { return $this->buttonClasses; } /** * Set front-end icon * * @return RequestHandler */ public function setIcon($icon) { $this->icon = $icon; return $this; } /** * Return front-end icon * * @return string */ public function getIcon() { return $this->icon; } /** * Set front-end label * * @return RequestHandler */ public function setLabel($label) { $this->label = $label; return $this; } /** * Return front-end label * * @return string */ public function getLabel() { return $this->label; } /** * Return i18n localized front-end label * * @return array */ public function getI18nLabel() { return _t('GRIDFIELD_BULK_MANAGER.HANDLER_LABEL', $this->getLabel()); } /** * Returns the URL for this RequestHandler. * * @author SilverStripe * * @see GridFieldDetailForm_ItemRequest * * @param string $action * * @return string */ public function Link($action = null) { return Controller::join_links($this->gridField->Link(), 'bulkAction', $action); } /** * Returns the list of record IDs selected in the front-end. * * @return array List of IDs */ public function getRecordIDList() { $vars = $this->request->requestVars(); return $vars['records']; } /** * Returns a DataList of the records selected in the front-end. * * @return DataList List of records */ public function getRecords() { $ids = $this->getRecordIDList(); if ($ids) { $class = $this->gridField->list->dataClass; return DataList::create($class)->byIDs($ids); } else { return false; } } } |