|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BB's Zend Framework 2 Components |
|
4
|
|
|
* |
|
5
|
|
|
* UI Components |
|
6
|
|
|
* |
|
7
|
|
|
* @package [MyApplication] |
|
8
|
|
|
* @subpackage BB's Zend Framework 2 Components |
|
9
|
|
|
* @subpackage UI Components |
|
10
|
|
|
* @author Björn Bartels <[email protected]> |
|
11
|
|
|
* @link https://gitlab.bjoernbartels.earth/groups/zf2 |
|
12
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
|
13
|
|
|
* @copyright copyright (c) 2016 Björn Bartels <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace UIComponents\View\Helper\Components; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
* render nothing |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
class Button extends Element |
|
24
|
|
|
{ |
|
25
|
|
|
protected $tagname = 'a'; |
|
26
|
|
|
|
|
27
|
|
|
protected $classnames = 'button btn'; |
|
28
|
|
|
|
|
29
|
|
|
protected $drop = false; |
|
30
|
|
|
|
|
31
|
|
|
protected $block = false; |
|
32
|
|
|
|
|
33
|
|
|
protected $active = false; |
|
34
|
|
|
|
|
35
|
|
|
protected $_tags = array('a','input','button'); |
|
36
|
|
|
|
|
37
|
|
|
protected $_sizes = array('xs','sm','lg'); |
|
38
|
|
|
protected $_foundations_sizes = array( |
|
39
|
|
|
'xs' => 'tiny', 'xs' => 'small', 'lg' => 'large', |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
protected $_types = array('default','primary','success','info','warning','alert','danger','link'); |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* View helper entry point: |
|
46
|
|
|
* Retrieves helper and optionally sets component options to operate on |
|
47
|
|
|
* |
|
48
|
|
|
* @param array|StdClass $options [optional] component options to operate on |
|
|
|
|
|
|
49
|
|
|
* @return self |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __invoke($options = array()) |
|
52
|
|
|
{ |
|
53
|
|
|
parent::__invoke($options); |
|
54
|
|
|
|
|
55
|
|
|
$component = clone $this; |
|
56
|
|
|
|
|
57
|
|
|
$component->setHeader('')->setFooter(''); |
|
58
|
|
|
|
|
59
|
|
|
// tag options |
|
60
|
|
|
if ( isset($options["tagname"]) && in_array(strtolower($options["tagname"]), $component->getTags()) ) { |
|
|
|
|
|
|
61
|
|
|
$component->setTagname(strtolower($options["tagname"])); |
|
62
|
|
|
} else { |
|
63
|
|
|
$component->setTagname('a'); |
|
64
|
|
|
} |
|
65
|
|
|
if ( isset($options["attributes"]) && is_array($options["attributes"]) ) { |
|
66
|
|
|
$component->setAttributes($options["attributes"]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// bootstrap options |
|
70
|
|
|
if ( isset($options["size"]) && in_array(strtolower($options["size"]), $component->getSizes()) ) { |
|
71
|
|
|
$component->addClass('btn-'.strtolower($options["size"]).' '.strtolower($this->_foundations_sizes["size"])); |
|
72
|
|
|
} |
|
73
|
|
|
if ( isset($options["type"]) && in_array(strtolower($options["type"]), $component->getTypes()) ) { |
|
74
|
|
|
$component->addClass('btn-'.strtolower($options["type"]).' '.strtolower($options["type"])); |
|
75
|
|
|
} else { |
|
76
|
|
|
$component->addClass('btn-default'); |
|
77
|
|
|
} |
|
78
|
|
|
if ( isset($options["drop"]) ) { |
|
79
|
|
|
$component->setDrop($options["drop"]); |
|
80
|
|
|
} |
|
81
|
|
|
if ( isset($options["block"]) ) { |
|
82
|
|
|
$component->setBlock($options["block"]); |
|
83
|
|
|
} |
|
84
|
|
|
if ( isset($options["active"]) ) { |
|
85
|
|
|
$component->setActive($options["active"]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($component->getBlock()) $component->addClass('btn-block expanded'); |
|
89
|
|
|
if ($component->getActive()) $component->addClass('active'); |
|
90
|
|
|
|
|
91
|
|
|
if ($component->getTagname() == 'a') { |
|
92
|
|
|
$component->setAttributes(array_merge_recursive($component->getAttributes(), array( |
|
93
|
|
|
'role' => 'button' |
|
94
|
|
|
))); |
|
95
|
|
|
if ( isset($options["disabled"]) ) { |
|
96
|
|
|
$component->addClass('disabled'); |
|
97
|
|
|
} |
|
98
|
|
|
} else { |
|
99
|
|
|
$component->setAttributes(array_merge_recursive($component->getAttributes(), array( |
|
100
|
|
|
'type' => 'button' |
|
101
|
|
|
))); |
|
102
|
|
|
if ( isset($options["disabled"]) ) { |
|
103
|
|
|
$component->setAttributes(array_merge_recursive($component->getAttributes(), array( |
|
104
|
|
|
'disabled' => 'disabled' |
|
105
|
|
|
))); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// tag content |
|
110
|
|
|
if ( isset($options["label"]) && !empty($options["label"]) ) { |
|
111
|
|
|
$component->setContent($options["label"]); |
|
112
|
|
|
} else if ( isset($options["content"]) && !empty($options["content"]) ) { |
|
113
|
|
|
$component->setContent($options["content"]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
//$component = clone $this; |
|
117
|
|
|
return $component; |
|
118
|
|
|
// return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// |
|
122
|
|
|
// private getters/setters |
|
123
|
|
|
// |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return the $_sizes |
|
|
|
|
|
|
127
|
|
|
*/ |
|
128
|
|
|
public function getSizes() { |
|
129
|
|
|
return $this->_sizes; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param multitype:string $_sizes |
|
|
|
|
|
|
134
|
|
|
*/ |
|
135
|
|
|
public function setSizes($_sizes) { |
|
136
|
|
|
$this->_sizes = $_sizes; |
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return the $_types |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getTypes() { |
|
144
|
|
|
return $this->_types; |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param multitype:string $_types |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setTypes($_types) { |
|
151
|
|
|
$this->_types = $_types; |
|
152
|
|
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return the $_tags |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getTags() { |
|
159
|
|
|
return $this->_tags; |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @param multitype:string $_tags |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setTags($_tags) { |
|
166
|
|
|
$this->_tags = $_tags; |
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
// |
|
172
|
|
|
// option getters/setters |
|
173
|
|
|
// |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return the $drop |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getDrop() { |
|
180
|
|
|
return $this->drop; |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param string $drop |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setDrop($drop) { |
|
187
|
|
|
if ( in_array(strtolower($drop), array('up','down'))) { |
|
188
|
|
|
$this->drop = $drop; |
|
189
|
|
|
} |
|
190
|
|
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return the $block |
|
195
|
|
|
*/ |
|
196
|
|
|
public function getBlock() { |
|
197
|
|
|
return $this->block; |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param boolean $block |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setBlock($block) { |
|
204
|
|
|
$this->block = !!$block; |
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return the $active |
|
210
|
|
|
*/ |
|
211
|
|
|
public function getActive() { |
|
212
|
|
|
return $this->active; |
|
|
|
|
|
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param boolean $active |
|
217
|
|
|
*/ |
|
218
|
|
|
public function setActive($active) { |
|
219
|
|
|
$this->active = !!$active; |
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
} |