1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\PureModal; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
6
|
|
|
use SilverStripe\Forms\DatalessField; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Custom modal action |
10
|
|
|
* Requires cms-actions to work out of the box |
11
|
|
|
*/ |
12
|
|
|
class PureModalAction extends DatalessField |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var FieldList |
16
|
|
|
*/ |
17
|
|
|
protected $fieldList; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A custom title for the dialog button |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $dialogButtonTitle; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Should it show the dialog button |
27
|
|
|
* @var boolean |
28
|
|
|
*/ |
29
|
|
|
protected $showDialogButton = true; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* An icon for this button |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $buttonIcon; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var boolean |
39
|
|
|
*/ |
40
|
|
|
protected $shouldRefresh = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Whether to place the button in a dot-menu. |
44
|
|
|
* @see https://github.com/lekoala/silverstripe-cms-actions |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
protected $dropUp = false; |
48
|
|
|
|
49
|
|
|
public function __construct($name, $title) |
50
|
|
|
{ |
51
|
|
|
$name = 'doCustomAction[' . $name . ']'; |
52
|
|
|
$this->title = $title; |
53
|
|
|
$this->name = $name; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the title with icon if set |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
protected function getButtonTitle() |
62
|
|
|
{ |
63
|
|
|
$title = $this->title; |
64
|
|
|
if ($this->buttonIcon) { |
65
|
|
|
$title = '<span class="font-icon-' . $this->buttonIcon . '"></span> ' . $title; |
66
|
|
|
} |
67
|
|
|
return $title; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the dialog button title with icon if set |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
protected function getDialogButtonTitle() |
76
|
|
|
{ |
77
|
|
|
$title = $this->buttonTitle ?: $this->title; |
78
|
|
|
if ($this->buttonIcon) { |
79
|
|
|
$title = '<span class="font-icon-' . $this->buttonIcon . '"></span> ' . $title; |
80
|
|
|
} |
81
|
|
|
return $title; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set dialog button customised button title |
86
|
|
|
* |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
|
public function setDialogButtonTitle($value) |
90
|
|
|
{ |
91
|
|
|
$this->buttonTitle = $value; |
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get an icon for this button |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getButtonIcon() |
102
|
|
|
{ |
103
|
|
|
return $this->buttonIcon; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set an icon for this button |
108
|
|
|
* |
109
|
|
|
* Feel free to use SilverStripeIcons constants |
110
|
|
|
* |
111
|
|
|
* @param string $buttonIcon An icon for this button |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setButtonIcon(string $buttonIcon) |
115
|
|
|
{ |
116
|
|
|
$this->buttonIcon = $buttonIcon; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get whether it must display the dialog button |
122
|
|
|
* |
123
|
|
|
* @return boolean |
124
|
|
|
*/ |
125
|
|
|
protected function getShowDialogButton() |
126
|
|
|
{ |
127
|
|
|
return $this->showDialogButton; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set whether it must display the dialog button |
132
|
|
|
* |
133
|
|
|
* @return self |
134
|
|
|
*/ |
135
|
|
|
public function setShowDialogButton($value) |
136
|
|
|
{ |
137
|
|
|
$this->showDialogButton = !!$value; |
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the value of fieldList |
145
|
|
|
* @return FieldList |
146
|
|
|
*/ |
147
|
|
|
public function getFieldList() |
148
|
|
|
{ |
149
|
|
|
return $this->fieldList; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set the value of fieldList |
154
|
|
|
* |
155
|
|
|
* @param FieldList $fieldList |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
|
|
public function setFieldList(FieldList $fieldList) |
159
|
|
|
{ |
160
|
|
|
$this->fieldList = $fieldList; |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get the dropUp value |
166
|
|
|
* Called by ActionsGridFieldItemRequest to determine placement |
167
|
|
|
* |
168
|
|
|
* @see https://github.com/lekoala/silverstripe-cms-actions |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
|
|
public function getDropUp() |
172
|
|
|
{ |
173
|
|
|
return $this->dropUp; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Set the value of dropUp |
178
|
|
|
* |
179
|
|
|
* @see https://github.com/lekoala/silverstripe-cms-actions |
180
|
|
|
* @param bool $is |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setDropUp($is) |
184
|
|
|
{ |
185
|
|
|
$this->dropUp = !!$is; |
186
|
|
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Required for cms-actions |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
public function actionName() |
194
|
|
|
{ |
195
|
|
|
return rtrim(str_replace('doCustomAction[', '', $this->name), ']'); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get the value of shouldRefresh |
200
|
|
|
* @return mixed |
201
|
|
|
*/ |
202
|
|
|
public function getShouldRefresh() |
203
|
|
|
{ |
204
|
|
|
return $this->shouldRefresh; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Set the value of shouldRefresh |
209
|
|
|
* |
210
|
|
|
* @param mixed $shouldRefresh |
211
|
|
|
* @return $this |
212
|
|
|
*/ |
213
|
|
|
public function setShouldRefresh($shouldRefresh) |
214
|
|
|
{ |
215
|
|
|
$this->shouldRefresh = $shouldRefresh; |
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function getModalID() |
220
|
|
|
{ |
221
|
|
|
return 'modal_' . $this->name; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function getTitle() |
225
|
|
|
{ |
226
|
|
|
return $this->title; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|