Complex classes like TbActiveForm often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TbActiveForm, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
72 | class TbActiveForm extends CActiveForm { |
||
73 | |||
74 | // Allowed form types. |
||
75 | const TYPE_VERTICAL = 'vertical'; |
||
76 | const TYPE_INLINE = 'inline'; |
||
77 | const TYPE_HORIZONTAL = 'horizontal'; |
||
78 | |||
79 | protected static $typeClasses = array ( |
||
80 | self::TYPE_VERTICAL => '', |
||
81 | self::TYPE_INLINE => '-inline', |
||
82 | self::TYPE_HORIZONTAL => '-horizontal', |
||
83 | ); |
||
84 | /** |
||
85 | * The form type. Allowed types are in `TYPE_*` constants. |
||
86 | * @var string |
||
87 | */ |
||
88 | public $type = self::TYPE_VERTICAL; |
||
89 | |||
90 | /** |
||
91 | * Prepend wrapper CSS class. |
||
92 | * @var string |
||
93 | */ |
||
94 | public $prependCssClass = 'input-group'; |
||
95 | |||
96 | /** |
||
97 | * Append wrapper CSS class. |
||
98 | * @var string |
||
99 | */ |
||
100 | public $appendCssClass = 'input-group'; |
||
101 | |||
102 | /** |
||
103 | * Add-on CSS class. |
||
104 | * @var string |
||
105 | */ |
||
106 | public $addOnCssClass = 'input-group-addon'; |
||
107 | |||
108 | /** |
||
109 | * Add-on wrapper tag. |
||
110 | * @var string |
||
111 | */ |
||
112 | public $addOnTag = 'span'; |
||
113 | |||
114 | /** |
||
115 | * Tag for wrapping field with prepended and/or appended data. |
||
116 | * @var string |
||
117 | */ |
||
118 | public $addOnWrapperTag = 'div'; |
||
119 | |||
120 | /** |
||
121 | * Hint CSS class. |
||
122 | * @var string |
||
123 | */ |
||
124 | public $hintCssClass = 'help-block'; |
||
125 | |||
126 | /** |
||
127 | * Hint wrapper tag. |
||
128 | * @var string |
||
129 | */ |
||
130 | public $hintTag = 'span'; |
||
131 | |||
132 | /** |
||
133 | * Whether to render field error after input. Only for vertical and horizontal types. |
||
134 | * @var bool |
||
135 | */ |
||
136 | public $showErrors = true; |
||
137 | |||
138 | /** |
||
139 | * Initializes the widget. |
||
140 | * This renders the form open tag. |
||
141 | */ |
||
142 | 2 | public function init() { |
|
143 | |||
144 | 2 | self::addCssClass($this->htmlOptions, 'form' . self::$typeClasses[$this->type]); |
|
145 | |||
146 | 2 | if (!isset($this->errorMessageCssClass)) { |
|
147 | 2 | $this->errorMessageCssClass = 'help-block error'; |
|
148 | 2 | } |
|
149 | 2 | if(!isset($this->clientOptions['errorCssClass'])){ |
|
150 | 2 | $this->clientOptions['errorCssClass'] = 'has-error'; |
|
151 | 2 | } |
|
152 | 2 | if(!isset($this->clientOptions['successCssClass'])){ |
|
153 | 2 | $this->clientOptions['successCssClass'] = 'has-success'; |
|
154 | 2 | } |
|
155 | 2 | if(!isset($this->clientOptions['inputContainer'])){ |
|
156 | 2 | $this->clientOptions['inputContainer'] = 'div.form-group'; |
|
157 | 2 | } |
|
158 | |||
159 | 2 | parent::init(); |
|
160 | 2 | } |
|
161 | |||
162 | /** |
||
163 | * Displays a summary of validation errors for one or several models. |
||
164 | * |
||
165 | * This method is a wrapper for {@link CActiveForm::errorSummary}. |
||
166 | * |
||
167 | * @param mixed $models The models whose input errors are to be displayed. This can be either a single model or an array of models. |
||
168 | * @param string $header A piece of HTML code that appears in front of the errors |
||
169 | * @param string $footer A piece of HTML code that appears at the end of the errors |
||
170 | * @param array $htmlOptions Additional HTML attributes to be rendered in the container div tag. |
||
171 | * @return string The error summary. Empty if no errors are found. |
||
172 | * @see CActiveForm::errorSummary |
||
173 | */ |
||
174 | 1 | public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array()) { |
|
175 | |||
176 | 1 | if (!isset($htmlOptions['class'])) { |
|
177 | 1 | $htmlOptions['class'] = 'alert alert-block alert-danger'; |
|
178 | 1 | } |
|
179 | |||
180 | 1 | return parent::errorSummary($models, $header, $footer, $htmlOptions); |
|
181 | } |
||
182 | |||
183 | /** |
||
184 | * Generates a url field group for a model attribute. |
||
185 | * |
||
186 | * This method is a wrapper for {@link CActiveForm::urlField} and {@link customFieldGroup}. |
||
187 | * Please check {@link CActiveForm::urlField} for detailed information about $htmlOptions argument. |
||
188 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
189 | * |
||
190 | * @param CModel $model The data model. |
||
191 | * @param string $attribute The attribute. |
||
192 | * @param array $options Group attributes. |
||
193 | * @return string The generated url field group. |
||
194 | * @see CActiveForm::urlField |
||
195 | * @see customFieldGroup |
||
196 | */ |
||
197 | 2 | public function urlFieldGroup($model, $attribute, $options = array()) { |
|
208 | |||
209 | /** |
||
210 | * Generates an email field group for a model attribute. |
||
211 | * |
||
212 | * This method is a wrapper for {@link CActiveForm::emailField} and {@link customFieldGroup}. |
||
213 | * Please check {@link CActiveForm::emailField} for detailed information about $htmlOptions argument. |
||
214 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
215 | * |
||
216 | * @param CModel $model The data model. |
||
217 | * @param string $attribute The attribute. |
||
218 | * @param array $options Group attributes. |
||
219 | * @return string the generated email field group. |
||
220 | * @see CActiveForm::emailField |
||
221 | * @see customFieldGroup |
||
222 | */ |
||
223 | 2 | public function emailFieldGroup($model, $attribute, $options = array()) { |
|
224 | |||
225 | 2 | $this->initOptions($options); |
|
226 | 2 | $widgetOptions = $options['widgetOptions']; |
|
227 | |||
228 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
229 | |||
230 | 2 | $fieldData = array(array($this, 'emailField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
231 | |||
232 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
233 | } |
||
234 | |||
235 | /** |
||
236 | * Generates a number field group for a model attribute. |
||
237 | * |
||
238 | * This method is a wrapper for {@link CActiveForm::numberField} and {@link customFieldGroup}. |
||
239 | * Please check {@link CActiveForm::numberField} for detailed information about $htmlOptions argument. |
||
240 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
241 | * |
||
242 | * @param CModel $model The data model. |
||
243 | * @param string $attribute The attribute. |
||
244 | * @param array $options Group attributes. |
||
245 | * @return string The generated number filed group. |
||
246 | * @see CActiveForm::numberField |
||
247 | * @see customFieldGroup |
||
248 | */ |
||
249 | 2 | public function numberFieldGroup($model, $attribute, $options = array()) { |
|
250 | |||
251 | 2 | $this->initOptions($options); |
|
252 | 2 | $widgetOptions = $options['widgetOptions']; |
|
253 | |||
254 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
255 | |||
256 | 2 | $fieldData = array(array($this, 'numberField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
257 | |||
258 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
259 | } |
||
260 | |||
261 | /** |
||
262 | * Generates a range field group for a model attribute. |
||
263 | * |
||
264 | * This method is a wrapper for {@link CActiveForm::rangeField} and {@link customFieldGroup}. |
||
265 | * Please check {@link CActiveForm::rangeField} for detailed information about $htmlOptions argument. |
||
266 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
267 | * |
||
268 | * @param CModel $model The data model. |
||
269 | * @param string $attribute The attribute. |
||
270 | * @param array $options Group attributes. |
||
271 | * @return string The generated range field group. |
||
272 | * @see CActiveForm::rangeField |
||
273 | * @see customFieldGroup |
||
274 | */ |
||
275 | 2 | public function rangeFieldGroup($model, $attribute, $options = array()) { |
|
276 | |||
277 | 2 | $this->initOptions($options); |
|
278 | 2 | $widgetOptions = $options['widgetOptions']; |
|
279 | |||
280 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
281 | |||
282 | 2 | $fieldData = array(array($this, 'rangeField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
283 | |||
284 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
285 | } |
||
286 | |||
287 | /** |
||
288 | * Generates a date field group for a model attribute. |
||
289 | * |
||
290 | * This method is a wrapper for {@link CActiveForm::dateField} and {@link customFieldGroup}. |
||
291 | * Please check {@link CActiveForm::dateField} for detailed information about $htmlOptions argument. |
||
292 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
293 | * |
||
294 | * @param CModel $model The data model. |
||
295 | * @param string $attribute The attribute. |
||
296 | * @param array $options Group attributes. |
||
297 | * @return string The generated date field group. |
||
298 | * @see CActiveForm::dateField |
||
299 | * @see customFieldGroup |
||
300 | */ |
||
301 | 2 | public function dateFieldGroup($model, $attribute, $options = array()) { |
|
302 | |||
303 | 2 | $this->initOptions($options); |
|
304 | 2 | $widgetOptions = $options['widgetOptions']; |
|
305 | |||
306 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
307 | |||
308 | 2 | $fieldData = array(array($this, 'dateField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
309 | |||
310 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
311 | } |
||
312 | |||
313 | /** |
||
314 | * Generates a time field group for a model attribute. |
||
315 | * |
||
316 | * This method is a wrapper for {@link CActiveForm::timeField} and {@link customFieldGroup}. |
||
317 | * Please check {@link CActiveForm::timeField} for detailed information about $htmlOptions argument. |
||
318 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
319 | * |
||
320 | * @param CModel $model The data model. |
||
321 | * @param string $attribute The attribute. |
||
322 | * @param array $options Group attributes. |
||
323 | * @return string The generated date field group. |
||
324 | * @see CActiveForm::timeField |
||
325 | * @see customFieldGroup |
||
326 | */ |
||
327 | 2 | public function timeFieldGroup($model, $attribute, $options = array()) { |
|
328 | |||
329 | 2 | $this->initOptions($options); |
|
330 | 2 | $widgetOptions = $options['widgetOptions']; |
|
331 | |||
332 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
333 | |||
334 | 2 | $fieldData = array(array($this, 'timeField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
335 | |||
336 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
337 | } |
||
338 | |||
339 | /** |
||
340 | * Generates a tel field group for a model attribute. |
||
341 | * |
||
342 | * This method is a wrapper for {@link CActiveForm::telField} and {@link customFieldGroup}. |
||
343 | * Please check {@link CActiveForm::telField} for detailed information about $htmlOptions argument. |
||
344 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
345 | * |
||
346 | * @param CModel $model The data model. |
||
347 | * @param string $attribute The attribute. |
||
348 | * @param array $options Group attributes. |
||
349 | * @return string The generated date field group. |
||
350 | * @see CActiveForm::telField |
||
351 | * @see customFieldGroup |
||
352 | */ |
||
353 | 2 | public function telFieldGroup($model, $attribute, $options = array()) { |
|
354 | |||
355 | 2 | $this->initOptions($options); |
|
356 | 2 | $widgetOptions = $options['widgetOptions']; |
|
357 | |||
358 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
359 | |||
360 | 2 | $fieldData = array(array($this, 'telField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
361 | |||
362 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
363 | } |
||
364 | |||
365 | /** |
||
366 | * Generates a text field group for a model attribute. |
||
367 | * |
||
368 | * This method is a wrapper for {@link CActiveForm::textField} and {@link customFieldGroup}. |
||
369 | * Please check {@link CActiveForm::textField} for detailed information about $htmlOptions argument. |
||
370 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
371 | * |
||
372 | * @param CModel $model The data model. |
||
373 | * @param string $attribute The attribute. |
||
374 | * @param array $options Group attributes. |
||
375 | * @return string The generated text field group. |
||
376 | * @see CActiveForm::textField |
||
377 | * @see customFieldGroup |
||
378 | */ |
||
379 | 2 | public function textFieldGroup($model, $attribute, $options = array()) { |
|
380 | |||
381 | 2 | $this->initOptions($options); |
|
382 | 2 | $widgetOptions = $options['widgetOptions']; |
|
383 | |||
384 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
385 | |||
386 | 2 | $fieldData = array(array($this, 'textField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
387 | |||
388 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
389 | } |
||
390 | |||
391 | /** |
||
392 | * Generates a search field group for a model attribute. |
||
393 | * |
||
394 | * This method is a wrapper for {@link CActiveForm::searchField} and {@link customFieldGroup}. |
||
395 | * Please check {@link CActiveForm::searchField} for detailed information about $htmlOptions argument. |
||
396 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
397 | * |
||
398 | * @param CModel $model The data model. |
||
399 | * @param string $attribute The attribute. |
||
400 | * @param array $options Group attributes. |
||
401 | * @return string The generated text field group. |
||
402 | * @see CActiveForm::searchField |
||
403 | * @see customFieldGroup |
||
404 | */ |
||
405 | 2 | public function searchFieldGroup($model, $attribute, $options = array()) { |
|
406 | |||
407 | 2 | $this->initOptions($options); |
|
408 | 2 | $widgetOptions = $options['widgetOptions']; |
|
409 | |||
410 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
411 | |||
412 | 2 | $fieldData = array(array($this, 'searchField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
413 | |||
414 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
415 | } |
||
416 | |||
417 | /** |
||
418 | * Generates a password field group for a model attribute. |
||
419 | * |
||
420 | * This method is a wrapper for {@link CActiveForm::passwordField} and {@link customFieldGroup}. |
||
421 | * Please check {@link CActiveForm::passwordField} for detailed information about $htmlOptions argument. |
||
422 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
423 | * |
||
424 | * @param CModel $model The data model. |
||
425 | * @param string $attribute The attribute. |
||
426 | * @param array $options Group attributes. |
||
427 | * @return string The generated password field group. |
||
428 | * @see CActiveForm::passwordField |
||
429 | * @see customFieldGroup |
||
430 | */ |
||
431 | 2 | public function passwordFieldGroup($model, $attribute, $options = array()) { |
|
432 | |||
433 | 2 | $this->initOptions($options); |
|
434 | 2 | $this->addCssClass($options['widgetOptions']['htmlOptions'], 'form-control'); |
|
435 | |||
436 | 2 | $fieldData = array(array($this, 'passwordField'), array($model, $attribute, $options['widgetOptions']['htmlOptions'])); |
|
437 | |||
438 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
439 | } |
||
440 | |||
441 | /** |
||
442 | * Generates a text area group for a model attribute. |
||
443 | * |
||
444 | * This method is a wrapper for {@link CActiveForm::textArea} and {@link customFieldGroup}. |
||
445 | * Please check {@link CActiveForm::textArea} for detailed information about $htmlOptions argument. |
||
446 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
447 | * |
||
448 | * @param CModel $model The data model. |
||
449 | * @param string $attribute The attribute. |
||
450 | * @param array $options Group attributes. |
||
451 | * @return string The generated text area group. |
||
452 | * @see CActiveForm::textArea |
||
453 | * @see customFieldGroup |
||
454 | */ |
||
455 | 2 | public function textAreaGroup($model, $attribute, $options = array()) { |
|
456 | |||
457 | 2 | $this->initOptions($options); |
|
458 | 2 | $this->addCssClass($options['widgetOptions']['htmlOptions'], 'form-control'); |
|
459 | |||
460 | 2 | $fieldData = array(array($this, 'textArea'), array($model, $attribute, $options['widgetOptions']['htmlOptions'])); |
|
461 | |||
462 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
463 | } |
||
464 | |||
465 | /** |
||
466 | * Generates a file field group for a model attribute. |
||
467 | * |
||
468 | * This method is a wrapper for {@link CActiveForm::fileField} and {@link customFieldGroup}. |
||
469 | * Please check {@link CActiveForm::fileField} for detailed information about $htmlOptions argument. |
||
470 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
471 | * |
||
472 | * @param CModel $model The data model. |
||
473 | * @param string $attribute The attribute. |
||
474 | * @param array $options Group attributes. |
||
475 | * @return string The generated file field group. |
||
476 | * @see CActiveForm::fileField |
||
477 | * @see customFieldGroup |
||
478 | */ |
||
479 | 2 | public function fileFieldGroup($model, $attribute, $options = array()) { |
|
480 | |||
481 | 2 | $this->initOptions($options); |
|
482 | 2 | $widgetOptions = $options['widgetOptions']; |
|
483 | |||
484 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
485 | |||
486 | 2 | $fieldData = array(array($this, 'fileField'), array($model, $attribute, $widgetOptions['htmlOptions'])); |
|
487 | |||
488 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
489 | } |
||
490 | |||
491 | /** |
||
492 | * Generates a radio button group for a model attribute. |
||
493 | * |
||
494 | * This method is a wrapper for {@link CActiveForm::radioButton} and {@link customFieldGroup}. |
||
495 | * Please check {@link CActiveForm::radioButton} for detailed information about $htmlOptions argument. |
||
496 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
497 | * |
||
498 | * @param CModel $model The data model. |
||
499 | * @param string $attribute The attribute. |
||
500 | * @param array $options Group attributes. |
||
501 | * @return string The generated radio button group. |
||
502 | * @see CActiveForm::radioButton |
||
503 | * @see customFieldGroup |
||
504 | */ |
||
505 | 3 | public function radioButtonGroup($model, $attribute, $options = array()) { |
|
506 | |||
507 | 3 | $this->initOptions($options); |
|
508 | 3 | $widgetOptions = $options['widgetOptions']['htmlOptions']; |
|
509 | |||
510 | 3 | self::addCssClass($options['labelOptions'], 'radio'); |
|
511 | 3 | if( $this->type == self::TYPE_INLINE || (isset($options['inline']) && $options['inline']) ) |
|
512 | 3 | self::addCssClass($options['labelOptions'], 'radio-inline'); |
|
513 | |||
514 | 3 | $field = $this->radioButton($model, $attribute, $widgetOptions); |
|
515 | 3 | if ((!array_key_exists('uncheckValue', $widgetOptions) || isset($widgetOptions['uncheckValue'])) |
|
516 | 3 | && preg_match('/\<input.*?type="hidden".*?\>/', $field, $matches) |
|
517 | 3 | ) { |
|
518 | 2 | $hiddenField = $matches[0]; |
|
519 | 2 | $field = str_replace($hiddenField, '', $field); |
|
520 | 2 | } |
|
521 | |||
522 | 3 | $realAttribute = $attribute; |
|
523 | 3 | CHtml::resolveName($model, $realAttribute); |
|
524 | |||
525 | 3 | ob_start(); |
|
526 | 3 | if (isset($hiddenField)) echo $hiddenField; |
|
527 | 3 | echo CHtml::tag('label', $options['labelOptions'], false, false); |
|
528 | 3 | echo $field; |
|
529 | 3 | if (isset($options['label'])) { |
|
530 | if ($options['label']) |
||
531 | echo $options['label']; |
||
532 | } else |
||
533 | 3 | echo $model->getAttributeLabel($realAttribute); |
|
534 | 3 | echo CHtml::closeTag('label'); |
|
535 | 3 | $fieldData = ob_get_clean(); |
|
536 | |||
537 | 3 | $widgetOptions['label'] = ''; |
|
538 | |||
539 | 3 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
540 | } |
||
541 | |||
542 | /** |
||
543 | * Generates a checkbox group for a model attribute. |
||
544 | * |
||
545 | * This method is a wrapper for {@link CActiveForm::checkbox} and {@link customFieldGroup}. |
||
546 | * Please check {@link CActiveForm::checkbox} for detailed information about $htmlOptions argument. |
||
547 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
548 | * |
||
549 | * @param CModel $model The data model. |
||
550 | * @param string $attribute The attribute. |
||
551 | * @param array $options Group attributes. |
||
552 | * @return string The generated checkbox group. |
||
553 | * @see CActiveForm::checkbox |
||
554 | * @see customFieldGroup |
||
555 | */ |
||
556 | 3 | public function checkboxGroup($model, $attribute, $options = array()) { |
|
557 | |||
558 | 3 | $this->initOptions($options); |
|
559 | |||
560 | 3 | if ($this->type == self::TYPE_INLINE) |
|
561 | 3 | self::addCssClass($options['labelOptions'], 'inline'); |
|
562 | |||
563 | 3 | $field = $this->checkbox($model, $attribute, $options['widgetOptions']['htmlOptions']); |
|
564 | 3 | if ((!array_key_exists('uncheckValue', $options['widgetOptions']) || isset($options['widgetOptions']['uncheckValue'])) |
|
565 | 3 | && preg_match('/\<input.*?type="hidden".*?\>/', $field, $matches) |
|
566 | 3 | ) { |
|
567 | 2 | $hiddenField = $matches[0]; |
|
568 | 2 | $field = str_replace($hiddenField, '', $field); |
|
569 | 2 | } |
|
570 | |||
571 | 3 | $realAttribute = $attribute; |
|
572 | 3 | CHtml::resolveName($model, $realAttribute); |
|
573 | |||
574 | 3 | ob_start(); |
|
575 | 3 | echo '<div class="checkbox">'; |
|
576 | 3 | if (isset($hiddenField)) echo $hiddenField; |
|
577 | 3 | echo CHtml::tag('label', $options['labelOptions'], false, false); |
|
578 | 3 | echo $field; |
|
579 | 3 | if (isset($options['label'])) { |
|
580 | if ($options['label']) |
||
581 | echo $options['label']; |
||
582 | } else |
||
583 | 3 | echo ' '.$model->getAttributeLabel($realAttribute); |
|
584 | 3 | echo CHtml::closeTag('label'); |
|
585 | 3 | echo '</div>'; |
|
586 | 3 | $fieldData = ob_get_clean(); |
|
587 | |||
588 | 3 | $options['label'] = ''; |
|
589 | |||
590 | 3 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
591 | } |
||
592 | |||
593 | /** |
||
594 | * Generates a dropdown list group for a model attribute. |
||
595 | * |
||
596 | * This method is a wrapper for {@link CActiveForm::dropDownList} and {@link customFieldGroup}. |
||
597 | * Please check {@link CActiveForm::dropDownList} for detailed information about $htmlOptions argument. |
||
598 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
599 | * |
||
600 | * @param CModel $model The data model. |
||
601 | * @param string $attribute The attribute. |
||
602 | * @param array $options Group attributes. |
||
603 | * @return string The generated drop down list group. |
||
604 | * @see CActiveForm::dropDownList |
||
605 | * @see customFieldGroup |
||
606 | */ |
||
607 | 2 | public function dropDownListGroup($model, $attribute, $options = array()) { |
|
608 | |||
609 | 2 | $this->initOptions($options, true); |
|
610 | 2 | $widgetOptions = $options['widgetOptions']; |
|
611 | |||
612 | |||
613 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
614 | |||
615 | 2 | $fieldData = array(array($this, 'dropDownList'), array($model, $attribute, $widgetOptions['data'], $widgetOptions['htmlOptions'])); |
|
616 | |||
617 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
618 | } |
||
619 | |||
620 | /** |
||
621 | * Generates a list box group for a model attribute. |
||
622 | * |
||
623 | * This method is a wrapper for {@link CActiveForm::listBox} and {@link customFieldGroup}. |
||
624 | * Please check {@link CActiveForm::listBox} for detailed information about $htmlOptions argument. |
||
625 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
626 | * |
||
627 | * @param CModel $model The data model. |
||
628 | * @param string $attribute The attribute. |
||
629 | * @param array $options Group attributes. |
||
630 | * @return string The generated list box group. |
||
631 | * @see CActiveForm::listBox |
||
632 | * @see customFieldGroup |
||
633 | */ |
||
634 | 2 | public function listBoxGroup($model, $attribute, $options = array()) { |
|
635 | |||
636 | 2 | $this->initOptions($options, true); |
|
637 | 2 | $widgetOptions = $options['widgetOptions']; |
|
638 | |||
639 | 2 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
640 | |||
641 | 2 | $fieldData = array(array($this, 'listBox'), array($model, $attribute, $widgetOptions['data'], $widgetOptions['htmlOptions'])); |
|
642 | |||
643 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
644 | } |
||
645 | |||
646 | /** |
||
647 | * Generates a checkbox list group for a model attribute. |
||
648 | * |
||
649 | * This method is a wrapper for {@link CActiveForm::checkboxList} and {@link customFieldGroup}. |
||
650 | * Please check {@link CActiveForm::checkboxList} for detailed information about $htmlOptions argument. |
||
651 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
652 | * |
||
653 | * @param CModel $model The data model. |
||
654 | * @param string $attribute The attribute. |
||
655 | * @param array $options Group attributes. |
||
656 | * @return string The generated checkbox list group. |
||
657 | * @see CActiveForm::checkboxList |
||
658 | * @see customFieldGroup |
||
659 | */ |
||
660 | 2 | public function checkboxListGroup($model, $attribute, $options = array()) { |
|
661 | |||
662 | 2 | $this->initOptions($options, true); |
|
663 | |||
664 | 2 | $widgetOptions = $options['widgetOptions']['htmlOptions']; |
|
665 | |||
666 | |||
667 | 2 | if (!isset($widgetOptions['labelOptions']['class'])) |
|
668 | 2 | $widgetOptions['labelOptions']['class'] = 'checkbox'; |
|
669 | |||
670 | 2 | if(isset($options['inline']) && $options['inline']) |
|
671 | 2 | $widgetOptions['labelOptions']['class'] = 'checkbox-inline'; |
|
672 | |||
673 | 2 | if (!isset($widgetOptions['template'])) |
|
674 | 2 | $widgetOptions['template'] = '{beginLabel}{input}{labelTitle}{endLabel}'; |
|
675 | |||
676 | 2 | if (!isset($widgetOptions['separator'])) |
|
677 | 2 | $widgetOptions['separator'] = "\n"; |
|
678 | |||
679 | 2 | $data = $options['widgetOptions']['data']; |
|
680 | |||
681 | 2 | $fieldData = array(array($this, 'checkboxList'), array($model, $attribute, $data, $widgetOptions)); |
|
682 | |||
683 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
684 | } |
||
685 | |||
686 | /** |
||
687 | * Generates a radio button list group for a model attribute. |
||
688 | * |
||
689 | * This method is a wrapper for {@link CActiveForm::radioButtonList} and {@link customFieldGroup}. |
||
690 | * Please check {@link CActiveForm::radioButtonList} for detailed information about $htmlOptions argument. |
||
691 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
692 | * |
||
693 | * @param CModel $model The data model. |
||
694 | * @param string $attribute The attribute. |
||
695 | * @param array $options Group attributes. |
||
696 | * @return string The generated radio button list group. |
||
697 | * @see CActiveForm::radioButtonList |
||
698 | * @see customFieldGroup |
||
699 | */ |
||
700 | 2 | public function radioButtonListGroup($model, $attribute, $options = array()) { |
|
701 | |||
702 | 2 | $this->initOptions($options, true); |
|
703 | |||
704 | 2 | $widgetOptions = $options['widgetOptions']['htmlOptions']; |
|
705 | |||
706 | |||
707 | 2 | if (!isset($widgetOptions['labelOptions']['class'])) |
|
708 | 2 | $widgetOptions['labelOptions']['class'] = 'radio'; |
|
709 | |||
710 | 2 | if(isset($options['inline']) && $options['inline']) |
|
711 | 2 | $widgetOptions['labelOptions']['class'] = 'checkbox-inline'; |
|
712 | |||
713 | 2 | if (!isset($widgetOptions['template'])) |
|
714 | 2 | $widgetOptions['template'] = '{beginLabel}{input}{labelTitle}{endLabel}'; |
|
715 | |||
716 | 2 | if (!isset($widgetOptions['separator'])) |
|
717 | 2 | $widgetOptions['separator'] = "\n"; |
|
718 | |||
719 | 2 | $data = $options['widgetOptions']['data']; |
|
720 | |||
721 | 2 | $fieldData = array(array($this, 'radioButtonList'), array($model, $attribute, $data, $widgetOptions)); |
|
722 | |||
723 | 2 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
724 | } |
||
725 | |||
726 | /** |
||
727 | * Generates a toggle button group for a model attribute. |
||
728 | * |
||
729 | * This method is a wrapper for {@link TbToggleButton} widget and {@link customFieldGroup}. |
||
730 | * Please check {@link TbToggleButton} documentation for detailed information about $widgetOptions. |
||
731 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
732 | * |
||
733 | * @param CModel $model The data model. |
||
734 | * @param string $attribute The attribute. |
||
735 | * @param array $options Group attributes. |
||
736 | * @return string The generated toggle button group. |
||
737 | * @see TbToggleButton |
||
738 | * @see customFieldGroup |
||
739 | */ |
||
740 | 1 | public function switchGroup($model, $attribute, $options = array()) { |
|
744 | |||
745 | /** |
||
746 | * Generates a date picker group for a model attribute. |
||
747 | * |
||
748 | * This method is a wrapper for {@link TbDatePicker} widget and {@link customFieldGroup}. |
||
749 | * Please check {@link TbDatePicker} documentation for detailed information about $widgetOptions. |
||
750 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
751 | * |
||
752 | * @param CModel $model The data model. |
||
753 | * @param string $attribute The attribute. |
||
754 | * @param array $options Group attributes. |
||
755 | * @return string The generated date picker group. |
||
756 | * @see TbDatePicker |
||
757 | * @see customFieldGroup |
||
758 | */ |
||
759 | 2 | public function datePickerGroup($model, $attribute, $options = array()) { |
|
763 | |||
764 | /** |
||
765 | * Generates a date range picker group for a model attribute. |
||
766 | * |
||
767 | * This method is a wrapper for {@link TbDateRangePicker} widget and {@link customFieldGroup}. |
||
768 | * Please check {@link TbDateRangePicker} documentation for detailed information about $widgetOptions. |
||
769 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
770 | * |
||
771 | * @param CModel $model The data model. |
||
772 | * @param string $attribute The attribute. |
||
773 | * @param array $options Group attributes. |
||
774 | * @return string The generated date range picker group. |
||
775 | * @see TbDateRangePicker |
||
776 | * @see customFieldGroup |
||
777 | */ |
||
778 | 2 | public function dateRangeGroup($model, $attribute, $options = array()) { |
|
782 | |||
783 | /** |
||
784 | * Generates a time picker group for a model attribute. |
||
785 | * |
||
786 | * This method is a wrapper for {@link TbTimePicker} widget and {@link customFieldGroup}. |
||
787 | * Please check {@link TbTimePicker} documentation for detailed information about $widgetOptions. |
||
788 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
789 | * |
||
790 | * @param CModel $model The data model. |
||
791 | * @param string $attribute The attribute. |
||
792 | * @param array $options Group attributes. |
||
793 | * @return string The generated time picker group. |
||
794 | * @see TbTimePicker |
||
795 | * @see customFieldGroup |
||
796 | */ |
||
797 | 2 | public function timePickerGroup($model, $attribute, $options = array()) { |
|
801 | |||
802 | /** |
||
803 | * Generates a date-time picker group for a model attribute. |
||
804 | * |
||
805 | * This method is a wrapper for {@link TbDateTimePicker} widget and {@link customFieldGroup}. |
||
806 | * Please check {@link TbDateTimePicker} documentation for detailed information about $widgetOptions. |
||
807 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
808 | * |
||
809 | * @param CModel $model The data model. |
||
810 | * @param string $attribute The attribute. |
||
811 | * @param array $options Group attributes. |
||
812 | * @return string The generated date-time picker group. |
||
813 | * @see TbDateTimePicker |
||
814 | * @see customFieldGroup |
||
815 | */ |
||
816 | 2 | public function dateTimePickerGroup($model, $attribute, $options = array()) { |
|
817 | |||
818 | 2 | return $this->widgetGroupInternal('booster.widgets.TbDateTimePicker', $model, $attribute, $options); |
|
819 | } |
||
820 | |||
821 | /** |
||
822 | * Generates a select2 group for a model attribute. |
||
823 | * |
||
824 | * This method is a wrapper for {@link TbSelect2} widget and {@link customFieldGroup}. |
||
825 | * Please check {@link TbSelect2} documentation for detailed information about $widgetOptions. |
||
826 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
827 | * |
||
828 | * @param CModel $model The data model. |
||
829 | * @param string $attribute The attribute. |
||
830 | * @param array $options Group attributes. |
||
831 | * @return string The generated select2 group. |
||
832 | * @see TbSelect2 |
||
833 | * @see customFieldGroup |
||
834 | */ |
||
835 | 2 | public function select2Group($model, $attribute, $options = array()) { |
|
836 | |||
837 | 2 | return $this->widgetGroupInternal('booster.widgets.TbSelect2', $model, $attribute, $options); |
|
838 | } |
||
839 | |||
840 | /** |
||
841 | * Generates a chosen group for a model attribute. |
||
842 | * |
||
843 | * This method is a wrapper for {@link TbChosen} widget and {@link customFieldGroup}. |
||
844 | * Please check {@link TbChosen} documentation for detailed information about $widgetOptions. |
||
845 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
846 | * |
||
847 | * @param CModel $model The data model. |
||
848 | * @param string $attribute The attribute. |
||
849 | * @param array $options Group attributes. |
||
850 | * @return string The generated chosen group. |
||
851 | * @see TbChosen |
||
852 | * @see customFieldGroup |
||
853 | */ |
||
854 | public function chosenGroup($model, $attribute, $options = array()) { |
||
855 | |||
856 | return $this->widgetGroupInternal('booster.widgets.TbChosen', $model, $attribute, $options); |
||
857 | } |
||
858 | |||
859 | /** |
||
860 | * Generates a redactor editor group for a model attribute. |
||
861 | * |
||
862 | * This method is a wrapper for {@link TbRedactorJs} widget and {@link customFieldGroup}. |
||
863 | * Please check {@link TbRedactorJs} documentation for detailed information about $widgetOptions. |
||
864 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
865 | * |
||
866 | * @param CModel $model The data model. |
||
867 | * @param string $attribute The attribute. |
||
868 | * @param array $options Group attributes. |
||
869 | * @return string The generated redactor editor group. |
||
870 | * @see TbRedactorJs |
||
871 | * @see customFieldGroup |
||
872 | */ |
||
873 | 2 | public function redactorGroup($model, $attribute, $options = array()) { |
|
877 | |||
878 | /** |
||
879 | * Generates a html5 editor group for a model attribute. |
||
880 | * |
||
881 | * This method is a wrapper for {@link TbHtml5Editor} widget and {@link customFieldGroup}. |
||
882 | * Please check {@link TbHtml5Editor} documentation for detailed information about $widgetOptions. |
||
883 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
884 | * |
||
885 | * @param CModel $model The data model. |
||
886 | * @param string $attribute The attribute. |
||
887 | * @param array $options Group attributes. |
||
888 | * @return string The generated html5 editor group. |
||
889 | * @see TbHtml5Editor |
||
890 | * @see customFieldGroup |
||
891 | */ |
||
892 | 2 | public function html5EditorGroup($model, $attribute, $options = array()) { |
|
896 | |||
897 | /** |
||
898 | * Generates a markdown editor group for a model attribute. |
||
899 | * |
||
900 | * This method is a wrapper for {@link TbMarkdownEditorJs} widget and {@link customFieldGroup}. |
||
901 | * Please check {@link TbMarkdownEditorJs} documentation for detailed information about $widgetOptions. |
||
902 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
903 | * |
||
904 | * @param CModel $model The data model. |
||
905 | * @param string $attribute The attribute. |
||
906 | * @param array $options Group attributes. |
||
907 | * @return string The generated markdown editor group. |
||
908 | * @see TbMarkdownEditorJs |
||
909 | * @see customFieldGroup |
||
910 | */ |
||
911 | 1 | public function markdownEditorGroup($model, $attribute, $options = array()) { |
|
915 | |||
916 | /** |
||
917 | * Generates a CKEditor group for a model attribute. |
||
918 | * |
||
919 | * This method is a wrapper for {@link TbCKEditor} widget and {@link customFieldGroup}. |
||
920 | * Please check {@link TbCKEditor} documentation for detailed information about $widgetOptions. |
||
921 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
922 | * |
||
923 | * @param CModel $model The data model. |
||
924 | * @param string $attribute The attribute. |
||
925 | * @param array $options Group attributes. |
||
926 | * @return string The generated CKEditor group. |
||
927 | * @see TbCKEditor |
||
928 | * @see customFieldGroup |
||
929 | */ |
||
930 | 2 | public function ckEditorGroup($model, $attribute, $options = array()) { |
|
934 | |||
935 | /** |
||
936 | * Generates a type-ahead group for a model attribute. |
||
937 | * |
||
938 | * This method is a wrapper for {@link TbTypeahead} widget and {@link customFieldGroup}. |
||
939 | * Please check {@link TbTypeahead} documentation for detailed information about $widgetOptions. |
||
940 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
941 | * |
||
942 | * @param CModel $model The data model. |
||
943 | * @param string $attribute The attribute. |
||
944 | * @param array $options Group attributes. |
||
945 | * @return string The generated type-ahead group. |
||
946 | * @see TbTypeahead |
||
947 | * @see customFieldGroup |
||
948 | */ |
||
949 | 2 | public function typeAheadGroup($model, $attribute, $options = array()) { |
|
950 | |||
951 | 2 | return $this->widgetGroupInternal('booster.widgets.TbTypeahead', $model, $attribute, $options); |
|
952 | } |
||
953 | |||
954 | /** |
||
955 | * Generates a masked text field group for a model attribute. |
||
956 | * |
||
957 | * This method is a wrapper for {@link CMaskedTextField} widget and {@link customFieldGroup}. |
||
958 | * Please check {@link CMaskedTextField} documentation for detailed information about $widgetOptions. |
||
959 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
960 | * |
||
961 | * @param CModel $model The data model. |
||
962 | * @param string $attribute The attribute. |
||
963 | * @param array $options Group attributes. |
||
964 | * @return string The generated masked text field group. |
||
965 | * @see CMaskedTextField |
||
966 | * @see customFieldGroup |
||
967 | */ |
||
968 | 2 | public function maskedTextFieldGroup($model, $attribute, $options = array()) { |
|
969 | |||
970 | 2 | return $this->widgetGroupInternal('CMaskedTextField', $model, $attribute, $options); |
|
971 | } |
||
972 | |||
973 | /** |
||
974 | * Generates a color picker field group for a model attribute. |
||
975 | * |
||
976 | * This method is a wrapper for {@link TbColorPicker} widget and {@link customFieldGroup}. |
||
977 | * Please check {@link TbColorPicker} documentation for detailed information about $widgetOptions. |
||
978 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
979 | * |
||
980 | * @param CModel $model The data model. |
||
981 | * @param string $attribute The attribute. |
||
982 | * @param array $options Group attributes. |
||
983 | * @return string The generated color picker group. |
||
984 | * @see TbColorPicker |
||
985 | * @see customFieldGroup |
||
986 | */ |
||
987 | 2 | public function colorPickerGroup($model, $attribute, $options = array()) { |
|
988 | |||
989 | 2 | return $this->widgetGroupInternal('booster.widgets.TbColorPicker', $model, $attribute, $options); |
|
990 | } |
||
991 | |||
992 | /** |
||
993 | * Generates a color picker field group for a model attribute. |
||
994 | * |
||
995 | * This method is a wrapper for {@link CCaptcha} widget, {@link textField} and {@link customFieldGroup}. |
||
996 | * Please check {@link CCaptcha} documentation for detailed information about $widgetOptions. |
||
997 | * Read detailed information about $htmlOptions in {@link CActiveForm::textField} method. |
||
998 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
999 | * |
||
1000 | * @param CModel $model The data model. |
||
1001 | * @param string $attribute The attribute. |
||
1002 | * @param array $options Group attributes. |
||
1003 | * @return string The generated color picker group. |
||
1004 | * @see CCaptcha |
||
1005 | * @see CActiveForm::textField |
||
1006 | * @see customFieldGroup |
||
1007 | */ |
||
1008 | 1 | public function captchaGroup($model, $attribute, $options = array()) { |
|
1009 | |||
1010 | 1 | $this->initOptions($options); |
|
1011 | 1 | $widgetOptions = $options['widgetOptions']; |
|
1012 | |||
1013 | 1 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
1014 | |||
1015 | 1 | $fieldData = $this->textField($model, $attribute, $widgetOptions['htmlOptions']); |
|
1016 | 1 | unset($widgetOptions['htmlOptions']); |
|
1017 | 1 | $fieldData .= '<div class="captcha">' . $this->owner->widget('CCaptcha', $widgetOptions, true) . '</div>'; |
|
1018 | |||
1019 | 1 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
1020 | } |
||
1021 | |||
1022 | /** |
||
1023 | * Generates a Pass*Field group for a model attribute. |
||
1024 | * |
||
1025 | * This method is a wrapper for {@link TbPassfield} widget and {@link customFieldGroup}. |
||
1026 | * Please check {@link TbPassfield} documentation for detailed information about $widgetOptions. |
||
1027 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
1028 | * |
||
1029 | * @param CModel $model The data model. |
||
1030 | * @param string $attribute The attribute. |
||
1031 | * @param array $options Group attributes. |
||
1032 | * @return string The generated color picker group. |
||
1033 | * @see TbPassfield |
||
1034 | * @see customFieldGroup |
||
1035 | */ |
||
1036 | 2 | public function passFieldGroup($model, $attribute, $options = array()) { |
|
1037 | |||
1038 | 2 | return $this->widgetGroupInternal('booster.widgets.TbPassfield', $model, $attribute, $options); |
|
1039 | } |
||
1040 | |||
1041 | /** |
||
1042 | * Generates a custom field group for a model attribute. |
||
1043 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
1044 | * |
||
1045 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() |
||
1046 | * function. |
||
1047 | * @param CModel $model The data model. |
||
1048 | * @param string $attribute The attribute. |
||
1049 | * @param array $options Group attributes. |
||
1050 | * @return string The generated custom filed group. |
||
1051 | * @see call_user_func_array |
||
1052 | */ |
||
1053 | 1 | public function customFieldGroup($fieldData, $model, $attribute, $options = array()) { |
|
1054 | |||
1055 | 1 | $this->initOptions($options); |
|
1056 | |||
1057 | 1 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
1058 | } |
||
1059 | |||
1060 | /** |
||
1061 | * Generates a widget group for a model attribute. |
||
1062 | * |
||
1063 | * This method is a wrapper for {@link CBaseController::widget} and {@link customFieldGroup}. |
||
1064 | * Read detailed information about $widgetOptions in $properties argument of {@link CBaseController::widget} method. |
||
1065 | * About $options argument parameters see {@link TbActiveForm} documentation. |
||
1066 | * |
||
1067 | * @param string $className The widget class name or class in dot syntax (e.g. application.widgets.MyWidget). |
||
1068 | * @param CModel $model The data model. |
||
1069 | * @param string $attribute The attribute. |
||
1070 | * @param array $options List of initial property values for the group (Property Name => Property Value). |
||
1071 | * @return string The generated widget group. |
||
1072 | * @see CBaseController::widget |
||
1073 | * @see customFieldGroup |
||
1074 | */ |
||
1075 | 1 | public function widgetGroup($className, $model, $attribute, $options = array()) { |
|
1076 | |||
1077 | 1 | $this->initOptions($options); |
|
1078 | 1 | $widgetOptions = isset($options['widgetOptions']) ? $options['widgetOptions'] : null; |
|
1079 | |||
1080 | 1 | $fieldData = array(array($this->owner, 'widget'), array($className, $widgetOptions, true)); |
|
1081 | |||
1082 | 1 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
1083 | } |
||
1084 | |||
1085 | /** |
||
1086 | * This is a intermediate method for widget-based group methods. |
||
1087 | * |
||
1088 | * @param string $className The widget class name or class in dot syntax (e.g. application.widgets.MyWidget). |
||
1089 | * @param CModel $model The data model. |
||
1090 | * @param string $attribute The attribute. |
||
1091 | * @param array $options Group attributes. |
||
1092 | * @return string The generated widget group. |
||
1093 | */ |
||
1094 | 1 | protected function widgetGroupInternal($className, &$model, &$attribute, &$options) { |
|
1095 | 1 | $this->initOptions($options); |
|
1096 | 1 | $widgetOptions = $options['widgetOptions']; |
|
1097 | 1 | $widgetOptions['model'] = $model; |
|
1098 | 1 | $widgetOptions['attribute'] = $attribute; |
|
1099 | |||
1100 | 1 | $this->addCssClass($widgetOptions['htmlOptions'], 'form-control'); |
|
1101 | |||
1102 | 1 | $fieldData = array(array($this->owner, 'widget'), array($className, $widgetOptions, true)); |
|
1103 | |||
1104 | 1 | return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options); |
|
1105 | } |
||
1106 | |||
1107 | /** |
||
1108 | * Generates a custom field group for a model attribute. |
||
1109 | * |
||
1110 | * It's base function for generating group with field. |
||
1111 | * |
||
1112 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() function. |
||
1113 | * @param CModel $model The data model. |
||
1114 | * @param string $attribute The attribute. |
||
1115 | * @param array $options Group attributes. |
||
1116 | * @return string The generated custom filed group. |
||
1117 | * @throws CException Raised on invalid form type. |
||
1118 | */ |
||
1119 | 22 | protected function customFieldGroupInternal(&$fieldData, &$model, &$attribute, &$options) { |
|
1120 | |||
1121 | 22 | $this->setDefaultPlaceholder($fieldData); |
|
1122 | |||
1123 | 22 | ob_start(); |
|
1124 | 22 | switch ($this->type) { |
|
1125 | 22 | case self::TYPE_HORIZONTAL: |
|
1126 | 1 | $this->horizontalGroup($fieldData, $model, $attribute, $options); |
|
1127 | 1 | break; |
|
1128 | |||
1129 | 21 | case self::TYPE_VERTICAL: |
|
1130 | 21 | $this->verticalGroup($fieldData, $model, $attribute, $options); |
|
1131 | 21 | break; |
|
1132 | |||
1133 | case self::TYPE_INLINE: |
||
1134 | $this->inlineGroup($fieldData, $model, $attribute, $options); |
||
1135 | break; |
||
1136 | |||
1137 | default: |
||
1138 | throw new CException('Invalid form type'); |
||
1139 | 22 | } |
|
1140 | |||
1141 | 22 | return ob_get_clean(); |
|
1142 | } |
||
1143 | |||
1144 | /** |
||
1145 | * Sets default placeholder value in case of CModel attribute depending on attribute label |
||
1146 | * |
||
1147 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() function. |
||
1148 | */ |
||
1149 | 22 | protected function setDefaultPlaceholder(&$fieldData) { |
|
1174 | |||
1175 | /** |
||
1176 | * Renders a horizontal custom field group for a model attribute. |
||
1177 | * |
||
1178 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() function. |
||
1179 | * @param CModel $model The data model. |
||
1180 | * @param string $attribute The attribute. |
||
1181 | * @param array $options Row options. |
||
1182 | */ |
||
1183 | 2 | protected function horizontalGroup(&$fieldData, &$model, &$attribute, &$options) { |
|
1184 | |||
1185 | 2 | $groupOptions = isset($options['groupOptions']) ? $options['groupOptions']: array(); |
|
1186 | 2 | self::addCssClass($groupOptions, 'form-group'); |
|
1187 | |||
1188 | 2 | $_attribute = $attribute; |
|
1189 | 2 | CHtml::resolveName($model, $_attribute); |
|
1190 | 2 | if ($model->hasErrors($_attribute) && $this->clientOptions['errorCssClass']) |
|
1191 | 1 | self::addCssClass($groupOptions, $this->clientOptions['errorCssClass']); |
|
1192 | |||
1193 | 1 | echo CHtml::openTag('div', $groupOptions); |
|
1194 | |||
1195 | 1 | if (!isset($options['labelOptions']['class']) || !preg_match('/col-\w{2}-\d{1,2}/', $options['labelOptions']['class'])) |
|
1196 | 1 | $this->addCssClass($options['labelOptions'], 'col-sm-3'); |
|
1197 | 1 | self::addCssClass($options['labelOptions'], 'control-label'); |
|
1198 | 1 | if (isset($options['label'])) { |
|
1199 | 1 | if (!empty($options['label'])) { |
|
1200 | echo CHtml::label($options['label'], CHtml::activeId($model, $attribute), $options['labelOptions']); |
||
1201 | } else { |
||
1202 | 1 | echo '<span class="col-sm-3"></span>'; |
|
1203 | } |
||
1204 | 1 | } else { |
|
1205 | 1 | echo $this->labelEx($model, $attribute, $options['labelOptions']); |
|
1206 | } |
||
1207 | |||
1208 | 1 | if(isset($options['wrapperHtmlOptions']) && !empty($options['wrapperHtmlOptions'])) |
|
1209 | 1 | $wrapperHtmlOptions = $options['wrapperHtmlOptions']; |
|
1210 | else |
||
1211 | 1 | $wrapperHtmlOptions = $options['wrapperHtmlOptions'] = array(); |
|
1212 | 1 | if (!isset($wrapperHtmlOptions['class']) || !preg_match('/col-\w{2}-\d{1,2}/', $wrapperHtmlOptions['class'])) |
|
1213 | 1 | $this->addCssClass($wrapperHtmlOptions, 'col-sm-9'); |
|
1214 | 1 | echo CHtml::openTag('div', $wrapperHtmlOptions); |
|
1215 | |||
1216 | 1 | if (!empty($options['prepend']) || !empty($options['append'])) { |
|
1217 | $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']); |
||
1218 | } |
||
1219 | |||
1220 | 1 | if (is_array($fieldData)) { |
|
1221 | 1 | echo call_user_func_array($fieldData[0], $fieldData[1]); |
|
1222 | 1 | } else { |
|
1223 | 1 | echo $fieldData; |
|
1224 | } |
||
1225 | |||
1226 | 1 | if (!empty($options['prepend']) || !empty($options['append'])) { |
|
1227 | $this->renderAddOnEnd($options['append'], $options['appendOptions']); |
||
1228 | } |
||
1229 | |||
1230 | 1 | if ($this->showErrors && $options['errorOptions'] !== false) { |
|
1231 | 1 | echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']); |
|
1232 | 1 | } |
|
1233 | |||
1234 | 1 | if (isset($options['hint'])) { |
|
1235 | self::addCssClass($options['hintOptions'], $this->hintCssClass); |
||
1236 | echo CHtml::tag($this->hintTag, $options['hintOptions'], $options['hint']); |
||
1237 | } |
||
1238 | |||
1239 | 1 | echo '</div></div>'; // controls, form-group |
|
1240 | 1 | } |
|
1241 | |||
1242 | /** |
||
1243 | * Renders a vertical custom field group for a model attribute. |
||
1244 | * |
||
1245 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() function. |
||
1246 | * @param CModel $model The data model. |
||
1247 | * @param string $attribute The attribute. |
||
1248 | * @param array $options Row options. |
||
1249 | * |
||
1250 | */ |
||
1251 | 22 | protected function verticalGroup(&$fieldData, &$model, &$attribute, &$options) { |
|
1252 | |||
1253 | 22 | $groupOptions = isset($options['groupOptions']) ? $options['groupOptions']: array(); |
|
1254 | 22 | self::addCssClass($groupOptions, 'form-group'); |
|
1255 | |||
1256 | 22 | $_attribute = $attribute; |
|
1257 | 22 | CHtml::resolveName($model, $_attribute); |
|
1258 | 22 | if ($model->hasErrors($_attribute) && $this->clientOptions['errorCssClass']) |
|
1259 | 21 | self::addCssClass($groupOptions, $this->clientOptions['errorCssClass']); |
|
1260 | |||
1261 | 21 | echo CHtml::openTag('div', $groupOptions); |
|
1262 | |||
1263 | 21 | self::addCssClass($options['labelOptions'], 'control-label'); |
|
1264 | 21 | if (isset($options['label'])) { |
|
1265 | 2 | if (!empty($options['label'])) { |
|
1266 | echo CHtml::label($options['label'], CHtml::activeId($model, $attribute), $options['labelOptions']); |
||
1267 | } |
||
1268 | 2 | } else { |
|
1269 | 19 | echo $this->labelEx($model, $attribute, $options['labelOptions']); |
|
1270 | } |
||
1271 | |||
1272 | 21 | if(isset($options['wrapperHtmlOptions']) && !empty($options['wrapperHtmlOptions'])) |
|
1273 | 21 | $wrapperHtmlOptions = $options['wrapperHtmlOptions']; |
|
1274 | else |
||
1275 | 21 | $wrapperHtmlOptions = $options['wrapperHtmlOptions'] = array(); |
|
1276 | 21 | echo CHtml::openTag('div', $wrapperHtmlOptions); |
|
1277 | |||
1278 | 21 | if (!empty($options['prepend']) || !empty($options['append'])) { |
|
1279 | $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']); |
||
1280 | } |
||
1281 | |||
1282 | 21 | if (is_array($fieldData)) { |
|
1283 | 16 | echo call_user_func_array($fieldData[0], $fieldData[1]); |
|
1284 | 16 | } else { |
|
1285 | 5 | echo $fieldData; |
|
1286 | } |
||
1287 | |||
1288 | 21 | if (!empty($options['prepend']) || !empty($options['append'])) { |
|
1289 | $this->renderAddOnEnd($options['append'], $options['appendOptions']); |
||
1290 | } |
||
1291 | |||
1292 | 21 | if ($this->showErrors && $options['errorOptions'] !== false) { |
|
1293 | 21 | echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']); |
|
1294 | 21 | } |
|
1295 | |||
1296 | 21 | if (isset($options['hint'])) { |
|
1297 | self::addCssClass($options['hintOptions'], $this->hintCssClass); |
||
1298 | echo CHtml::tag($this->hintTag, $options['hintOptions'], $options['hint']); |
||
1299 | } |
||
1300 | |||
1301 | 21 | echo '</div></div>'; |
|
1302 | 21 | } |
|
1303 | |||
1304 | /** |
||
1305 | * Renders a inline custom field group for a model attribute. |
||
1306 | * |
||
1307 | * @param array|string $fieldData Pre-rendered field as string or array of arguments for call_user_func_array() function. |
||
1308 | * @param CModel $model The data model. |
||
1309 | * @param string $attribute The attribute. |
||
1310 | * @param array $options Row options. |
||
1311 | */ |
||
1312 | 1 | protected function inlineGroup(&$fieldData, &$model, &$attribute, &$options) { |
|
1313 | |||
1314 | 1 | $groupOptions = isset($options['groupOptions']) ? $options['groupOptions']: array(); // array('class' => 'form-group'); |
|
1315 | 1 | self::addCssClass($groupOptions, 'form-group'); |
|
1316 | |||
1317 | 1 | echo CHtml::openTag('div', $groupOptions); |
|
1318 | |||
1319 | // TODO: do we need a wrapper for inline groups? |
||
1320 | 1 | if(isset($options['wrapperHtmlOptions']) && !empty($options['wrapperHtmlOptions'])) |
|
1321 | 1 | $wrapperHtmlOptions = $options['wrapperHtmlOptions']; |
|
1322 | else |
||
1323 | 1 | $wrapperHtmlOptions = $options['wrapperHtmlOptions'] = array(); |
|
1324 | 1 | echo CHtml::openTag('div', $wrapperHtmlOptions); |
|
1325 | |||
1326 | 1 | if (!empty($options['prepend']) || !empty($options['append'])) |
|
1327 | 1 | $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']); |
|
1328 | |||
1329 | 1 | if (is_array($fieldData)) { |
|
1330 | echo call_user_func_array($fieldData[0], $fieldData[1]); |
||
1331 | } else { |
||
1332 | 1 | echo $fieldData; |
|
1333 | } |
||
1334 | |||
1335 | 1 | if (!empty($options['prepend']) || !empty($options['append'])) |
|
1336 | 1 | $this->renderAddOnEnd($options['append'], $options['appendOptions']); |
|
1337 | |||
1338 | 1 | if ($this->showErrors && $options['errorOptions'] !== false) { |
|
1339 | 1 | echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']); |
|
1340 | 1 | } |
|
1341 | |||
1342 | 1 | echo "</div></div>\r\n"; |
|
1343 | 1 | } |
|
1344 | |||
1345 | /** |
||
1346 | * Renders add-on begin. |
||
1347 | * |
||
1348 | * @param string $prependText Prepended text. |
||
1349 | * @param string $appendText Appended text. |
||
1350 | * @param array $prependOptions Prepend options. |
||
1351 | */ |
||
1352 | 2 | protected function renderAddOnBegin($prependText, $appendText, $prependOptions) { |
|
1353 | |||
1354 | 2 | $wrapperCssClass = array(); |
|
1355 | 2 | if (!empty($prependText)) |
|
1356 | 2 | $wrapperCssClass[] = $this->prependCssClass; |
|
1357 | 2 | if (!empty($appendText)) |
|
1358 | 2 | $wrapperCssClass[] = $this->appendCssClass; |
|
1359 | |||
1360 | 2 | echo CHtml::tag($this->addOnWrapperTag, array('class' => implode(' ', $wrapperCssClass)), false, false); |
|
1361 | 2 | if (!empty($prependText)) { |
|
1362 | 2 | if (isset($prependOptions['isRaw']) && $prependOptions['isRaw']) { |
|
1363 | 1 | echo $prependText; |
|
1364 | 1 | } else { |
|
1365 | 2 | self::addCssClass($prependOptions, $this->addOnCssClass); |
|
1366 | 2 | echo CHtml::tag($this->addOnTag, $prependOptions, $prependText); |
|
1367 | } |
||
1368 | 2 | } |
|
1369 | 2 | } |
|
1370 | |||
1371 | /** |
||
1372 | * Renders add-on end. |
||
1373 | * |
||
1374 | * @param string $appendText Appended text. |
||
1375 | * @param array $appendOptions Append options. |
||
1376 | */ |
||
1377 | 2 | protected function renderAddOnEnd($appendText, $appendOptions) { |
|
1390 | |||
1391 | /** |
||
1392 | * @param array $options |
||
1393 | * @param bool $initData |
||
1394 | */ |
||
1395 | 24 | protected function initOptions(&$options, $initData = false) { |
|
1396 | |||
1397 | 24 | if (!isset($options['groupOptions'])) |
|
1398 | 24 | $options['groupOptions'] = array(); |
|
1399 | |||
1400 | 24 | if (!isset($options['labelOptions'])) |
|
1401 | 24 | $options['labelOptions'] = array(); |
|
1402 | |||
1403 | 24 | if (!isset($options['widgetOptions'])) |
|
1404 | 24 | $options['widgetOptions'] = array(); |
|
1405 | |||
1406 | 24 | if (!isset($options['widgetOptions']['htmlOptions'])) |
|
1407 | 24 | $options['widgetOptions']['htmlOptions'] = array(); |
|
1408 | |||
1409 | 24 | if($initData && !isset($options['widgetOptions']['data'])) |
|
1410 | 24 | $options['widgetOptions']['data'] = array(); |
|
1411 | |||
1412 | 24 | if (!isset($options['errorOptions'])) |
|
1413 | 24 | $options['errorOptions'] = array(); |
|
1414 | |||
1415 | 24 | if (!isset($options['prependOptions'])) |
|
1416 | 24 | $options['prependOptions'] = array(); |
|
1417 | |||
1418 | 24 | if (!isset($options['prepend'])) |
|
1419 | 24 | $options['prepend'] = null; |
|
1420 | |||
1421 | 24 | if (!isset($options['appendOptions'])) |
|
1422 | 24 | $options['appendOptions'] = array(); |
|
1423 | |||
1424 | 24 | if (!isset($options['append'])) |
|
1425 | 24 | $options['append'] = null; |
|
1426 | |||
1427 | 24 | if(!isset($options['enableAjaxValidation'])) |
|
1428 | 24 | $options['enableAjaxValidation'] = true; |
|
1429 | |||
1430 | 24 | if(!isset($options['enableClientValidation'])) |
|
1431 | 24 | $options['enableClientValidation'] = true; |
|
1432 | 24 | } |
|
1433 | |||
1434 | /** |
||
1435 | * Utility function for appending class names for a generic $htmlOptions array. |
||
1436 | * |
||
1437 | * @param array $htmlOptions |
||
1438 | * @param string $class |
||
1439 | */ |
||
1440 | 29 | protected static function addCssClass(&$htmlOptions, $class) { |
|
1452 | } |
||
1453 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.