1 | <?php |
||
43 | abstract class Element extends \ArrayObject |
||
44 | { |
||
45 | use HasAttributesTrait; |
||
46 | use HasDataTrait; |
||
47 | |||
48 | /** |
||
49 | * Name of the field (identifier of the element in the form's child list) |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $name; |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * @param string $name |
||
58 | * Name of the form element that will make it identifiable |
||
59 | * @param array $specs |
||
60 | * Specification for the element (attributes, parents, etc) |
||
61 | */ |
||
62 | 50 | public function __construct($name, $specs = array()) |
|
63 | { |
||
64 | 50 | $specs = array_merge($this->getDefaultSpecs(), $specs); |
|
65 | 50 | foreach ($specs as $key => $value) { |
|
66 | 42 | $this->set($key, $value); |
|
67 | 50 | } |
|
68 | 50 | $this->name = $name; |
|
69 | 50 | } |
|
70 | |||
71 | 44 | protected function inflectUnderscoreToClass($var) |
|
78 | |||
79 | 2 | public function get($key) |
|
88 | |||
89 | 44 | public function set($key, $value) |
|
99 | |||
100 | |||
101 | /** |
||
102 | * Returns the default element specifications |
||
103 | * The default specs are merged with the constructor specs |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | 8 | protected function getDefaultSpecs() |
|
111 | |||
112 | /** |
||
113 | * Retrieve the name of the form's element as registered within the form |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 14 | public function getName() |
|
121 | |||
122 | /** |
||
123 | * Sets the group this element belongs to |
||
124 | * |
||
125 | * @param null|string $group |
||
126 | * |
||
127 | * @return $this |
||
128 | */ |
||
129 | 1 | public function setGroup($group = null) |
|
135 | |||
136 | /** |
||
137 | * Retrieve the group this element belongs to |
||
138 | * |
||
139 | * @return null|string |
||
140 | */ |
||
141 | 9 | public function getGroup() |
|
145 | |||
146 | /** |
||
147 | * Sets the widget for this element |
||
148 | * |
||
149 | * @param null|string $widget |
||
150 | * |
||
151 | * @return $this |
||
152 | */ |
||
153 | 42 | public function setWidget($widget = null) |
|
159 | |||
160 | /** |
||
161 | * Retrieve the widget type for this element |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getWidget() |
||
169 | |||
170 | /** |
||
171 | * Sets the display priority for this element |
||
172 | * |
||
173 | * @param integer $priority |
||
174 | * |
||
175 | * @return $this |
||
176 | */ |
||
177 | 7 | public function setPosition($priority = 0) |
|
183 | |||
184 | /** |
||
185 | * Retrieve display position for this element |
||
186 | * |
||
187 | * @return integer |
||
188 | */ |
||
189 | public function getPosition() |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Prepares the input filter to receive data and be rendered |
||
197 | * It attaches the filters, validation rules, upload handler for the element |
||
198 | * |
||
199 | * @param InputFilter $inputFilter |
||
200 | */ |
||
201 | 9 | public function prepareInputFilter(InputFilter $inputFilter) |
|
210 | |||
211 | } |
||
212 |