Source of file GridFieldTableLink.php
Size: 6,149 Bytes - Last Modified: 2021-12-23T10:00:19+00:00
/var/www/docs.ssmods.com/process/src/src/GridFieldTableLink.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 | <?php namespace LeKoala\CmsActions; use ReflectionClass; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField_HTMLProvider; /** * Provide a simple way to declare links for GridField tables */ class GridFieldTableLink implements GridField_HTMLProvider { use DefaultLink; /** * Fragment to write the button to * @var string */ protected $targetFragment; /** * @var string */ protected $actionName; /** * @var string */ protected $buttonLabel; /** * @var string */ protected $fontIcon; /** * @var string */ protected $parentID; /** * @var string */ protected $confirm; /** * @var string */ protected $prompt; /** * @var string */ protected $promptDefault; /** * @var array */ protected $attributes = []; /** * @var boolean */ protected $noAjax = false; /** * @param string $targetFragment The HTML fragment to write the button into * @param string $buttonLabel */ public function __construct($targetFragment = "buttons-before-right", $buttonLabel = null, $actionName = null) { $this->targetFragment = $targetFragment; if ($buttonLabel) { $this->buttonLabel = $buttonLabel; } if ($actionName) { $this->actionName = $actionName; } } public function getActionName() { if ($this->actionName) { return $this->actionName; } $class = (new ReflectionClass(get_called_class()))->getShortName(); // ! without lowercase, in does not work return strtolower(str_replace('Button', '', $class)); } public function getButtonLabel() { return $this->buttonLabel; } /** * Place the export button in a <p> tag below the field */ public function getHTMLFragments($gridField) { $action = $this->getActionName(); $button = new CustomLink( $action, $this->getButtonLabel() ); $button->addExtraClass('btn btn-secondary action_' . $action); if ($this->fontIcon) { $button->addExtraClass('font-icon-' . $this->fontIcon); } if ($this->noAjax) { $button->setNoAjax($this->noAjax); } //TODO: replace prompt and confirm with inline js if ($this->prompt) { $button->setAttribute('data-prompt', $this->prompt); $promptDefault = $this->getPromptDefault(); if ($promptDefault) { $button->setAttribute('data-prompt-default', $promptDefault); } } if ($this->confirm) { $button->setAttribute('data-confirm', $this->confirm); } if ($this->newWindow) { $button->setNewWindow($this->newWindow); } if ($this->link) { $button->setLink($this->link); } foreach ($this->attributes as $attributeName => $attributeValue) { $button->setAttribute($attributeName, $attributeValue); } $button->setForm($gridField->getForm()); return array( $this->targetFragment => $button->Field() ); } /** * @param string $name * @param string $value * @return $this */ public function setAttribute($name, $value) { $this->attributes[$name] = $value; return $this; } /** * @param string $name * @return string */ public function getAttribute($name) { if (isset($this->attributes[$name])) { return $this->attributes[$name]; } return null; } public function getActions($gridField) { return array($this->getActionName()); } /** * Get the value of fontIcon * * @return string */ public function getFontIcon() { return $this->fontIcon; } /** * Set the value of fontIcon * * @param string $fontIcon * * @return $this */ public function setFontIcon($fontIcon) { $this->fontIcon = $fontIcon; return $this; } /** * Get the parent record id * * @return int */ public function getParentID() { return $this->parentID; } /** * Set the parent record id * * @param int $id * @return $this */ public function setParentID($id) { $this->parentID = $id; return $this; } /** * Get the value of confirm * * @return string */ public function getConfirm() { return $this->confirm; } /** * Set the value of confirm * * @param string $confirm * @return $this */ public function setConfirm($confirm) { $this->confirm = $confirm; return $this; } /** * Get the value of prompt * * @return string */ public function getPrompt() { return $this->prompt; } /** * Set the value of prompt * * @param string $prompt * @return $this */ public function setPrompt($prompt) { $this->prompt = $prompt; return $this; } /** * Get the value of promptDefault * * @return string */ public function getPromptDefault() { return $this->promptDefault; } /** * Set the value of promptDefault * * @param string $promptDefault * @return $this */ public function setPromptDefault($promptDefault) { $this->promptDefault = $promptDefault; return $this; } /** * Get the value of noAjax * @return boolean */ public function getNoAjax() { return $this->noAjax; } /** * Set the value of noAjax * * @param boolean $noAjax * @return $this */ public function setNoAjax($noAjax) { $this->noAjax = $noAjax; return $this; } } |