1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\CmsActions; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Common button functionnality that is shared between CustomAction and CustomLink |
7
|
|
|
*/ |
8
|
|
|
trait CustomButton |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Default classes applied in constructor |
12
|
|
|
* @config |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private static $default_classes = [ |
16
|
|
|
'btn', 'btn-info' |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Whether to place the button in a dot-menu |
21
|
|
|
* @var boolean |
22
|
|
|
*/ |
23
|
|
|
protected $dropUp = false; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* An icon for this button |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $buttonIcon; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The confirmation message |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $confirmation; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get the title of the link |
39
|
|
|
* Called by ActionsGridFieldItemRequest to build default message |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getTitle() |
44
|
|
|
{ |
45
|
|
|
return $this->title; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Set the value of title |
50
|
|
|
* |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
|
|
public function setTitle($title) |
54
|
|
|
{ |
55
|
|
|
$this->title = $title; |
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the dropUp malue |
61
|
|
|
* Called by ActionsGridFieldItemRequest to determine placement |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getDropUp() |
66
|
|
|
{ |
67
|
|
|
return $this->dropUp; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Set the value of dropUp |
72
|
|
|
* |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
|
|
public function setDropUp($is) |
76
|
|
|
{ |
77
|
|
|
$this->dropUp = !!$is; |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $type |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function setButtonType($type) |
87
|
|
|
{ |
88
|
|
|
if ($this->extraClasses) { |
89
|
|
|
foreach ($this->extraClasses as $k => $v) { |
90
|
|
|
if (strpos($k, 'btn-') !== false) { |
91
|
|
|
unset($this->extraClasses[$k]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$btn = "btn-$type"; |
97
|
|
|
$this->extraClasses[$btn] = $btn; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the title with icon if set |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function getButtonTitle() |
106
|
|
|
{ |
107
|
|
|
$title = $this->title; |
108
|
|
|
return $title; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get an icon for this button |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getButtonIcon() |
117
|
|
|
{ |
118
|
|
|
return $this->buttonIcon; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set an icon for this button |
123
|
|
|
* |
124
|
|
|
* Feel free to use SilverStripeIcons constants |
125
|
|
|
* |
126
|
|
|
* @param string $buttonIcon An icon for this button |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setButtonIcon(string $buttonIcon) |
130
|
|
|
{ |
131
|
|
|
$this->buttonIcon = $buttonIcon; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get the value of confirmation |
137
|
|
|
*/ |
138
|
|
|
public function getConfirmation() |
139
|
|
|
{ |
140
|
|
|
return $this->confirmation; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set the value of confirmation |
145
|
|
|
* |
146
|
|
|
* @param string|bool A confirm message or true for a generic message |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function setConfirmation($confirmation) |
150
|
|
|
{ |
151
|
|
|
if ($confirmation === true) { |
152
|
|
|
$confirmation = _t('CustomButton.CONFIRM_MESSAGE', 'Are you sure?'); |
153
|
|
|
} |
154
|
|
|
$this->confirmation = $confirmation; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|