| 1 | <?php |
||
| 2 | |||
| 3 | namespace LeKoala\Tabulator; |
||
| 4 | |||
| 5 | use SilverStripe\View\ArrayData; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Generic tool with a callable |
||
| 9 | */ |
||
| 10 | class GenericTabulatorTool extends AbstractTabulatorTool |
||
| 11 | { |
||
| 12 | protected $callable = null; |
||
| 13 | protected string $name = ''; |
||
| 14 | protected string $label = ''; |
||
| 15 | protected string $icon = ''; |
||
| 16 | protected string $buttonType = 'secondary'; |
||
| 17 | |||
| 18 | public function __construct($name, $label, $callable = null, $icon = '') |
||
| 19 | { |
||
| 20 | parent::__construct(); |
||
| 21 | |||
| 22 | $this->name = $name; |
||
| 23 | $this->label = $label; |
||
| 24 | $this->icon = $icon; |
||
| 25 | $this->callable = $callable; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function forTemplate() |
||
| 29 | { |
||
| 30 | $fontIcon = ''; |
||
| 31 | if ($this->icon) { |
||
| 32 | $fontIcon = ' font-icon-' . $this->icon; |
||
| 33 | } |
||
| 34 | $data = new ArrayData([ |
||
| 35 | 'ButtonName' => $this->label, |
||
| 36 | 'ButtonClasses' => 'btn-' . $this->buttonType . $fontIcon, |
||
| 37 | 'Icon' => $this->isAdmini() ? $this->icon : '', |
||
| 38 | ]); |
||
| 39 | return $this->renderWith($this->getViewerTemplates(), $data); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | |||
| 42 | public function index() |
||
| 43 | { |
||
| 44 | $callable = $this->callable; |
||
| 45 | return $callable($this->tabulatorGrid); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get the value of callable |
||
| 50 | */ |
||
| 51 | public function getCallable() |
||
| 52 | { |
||
| 53 | return $this->callable; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Set the value of callable |
||
| 58 | * |
||
| 59 | * @param callable $callable |
||
| 60 | */ |
||
| 61 | public function setCallable($callable): self |
||
| 62 | { |
||
| 63 | $this->callable = $callable; |
||
| 64 | return $this; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get the value of icon |
||
| 69 | */ |
||
| 70 | public function getIcon(): string |
||
| 71 | { |
||
| 72 | return $this->icon; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Set the value of icon |
||
| 77 | * |
||
| 78 | * @param string $icon |
||
| 79 | */ |
||
| 80 | public function setIcon($icon): self |
||
| 81 | { |
||
| 82 | $this->icon = $icon; |
||
| 83 | return $this; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Get the value of buttonType |
||
| 88 | */ |
||
| 89 | public function getButtonType(): string |
||
| 90 | { |
||
| 91 | return $this->buttonType; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Set the value of buttonType |
||
| 96 | * |
||
| 97 | * @param string $buttonType |
||
| 98 | */ |
||
| 99 | public function setButtonType($buttonType): self |
||
| 100 | { |
||
| 101 | $this->buttonType = $buttonType; |
||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | } |
||
| 105 |