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
|
|
|
* An icon for this button |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $buttonIcon; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The confirmation message |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $confirmation; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $noChangeTrack = true; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the title of the link |
38
|
|
|
* Called by ActionsGridFieldItemRequest to build default message |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getTitle() |
43
|
|
|
{ |
44
|
|
|
return $this->title; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set the value of title |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function setTitle($title) |
53
|
|
|
{ |
54
|
|
|
$this->title = $title; |
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $type |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function setButtonType($type) |
64
|
|
|
{ |
65
|
|
|
if ($this->extraClasses) { |
66
|
|
|
foreach ($this->extraClasses as $k => $v) { |
67
|
|
|
if (strpos($k, 'btn-') !== false) { |
68
|
|
|
unset($this->extraClasses[$k]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$btn = "btn-$type"; |
74
|
|
|
$this->extraClasses[$btn] = $btn; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the title with icon if set |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function getButtonTitle() |
83
|
|
|
{ |
84
|
|
|
$title = $this->title; |
85
|
|
|
if ($this->buttonIcon) { |
86
|
|
|
$title = '<span class="font-icon-' . $this->buttonIcon . '"></span> ' . $title; |
87
|
|
|
} |
88
|
|
|
return $title; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get an icon for this button |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getButtonIcon() |
97
|
|
|
{ |
98
|
|
|
return $this->buttonIcon; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set an icon for this button |
103
|
|
|
* |
104
|
|
|
* Feel free to use SilverStripeIcons constants |
105
|
|
|
* |
106
|
|
|
* @param string $buttonIcon An icon for this button |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
|
|
public function setButtonIcon(string $buttonIcon) |
110
|
|
|
{ |
111
|
|
|
$this->buttonIcon = $buttonIcon; |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the value of confirmation |
117
|
|
|
*/ |
118
|
|
|
public function getConfirmation() |
119
|
|
|
{ |
120
|
|
|
return $this->confirmation; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set the value of confirmation |
125
|
|
|
* |
126
|
|
|
* @param string|bool A confirm message or true for a generic message |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setConfirmation($confirmation) |
130
|
|
|
{ |
131
|
|
|
if ($confirmation === true) { |
132
|
|
|
$confirmation = _t('CustomButton.CONFIRM_MESSAGE', 'Are you sure?'); |
133
|
|
|
} |
134
|
|
|
$this->confirmation = $confirmation; |
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the value of noChangeTrack |
140
|
|
|
* @return bool |
141
|
|
|
*/ |
142
|
|
|
public function getNoChangeTrack() |
143
|
|
|
{ |
144
|
|
|
return $this->noChangeTrack; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Set the value of noChangeTrack |
149
|
|
|
* |
150
|
|
|
* @param bool $noChangeTrack |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
|
|
public function setNoChangeTrack($noChangeTrack) |
154
|
|
|
{ |
155
|
|
|
$this->noChangeTrack = $noChangeTrack; |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|