Complex classes like ActiveField 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 ActiveField, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class ActiveField extends Component |
||
25 | { |
||
26 | /** |
||
27 | * @var ActiveForm the form that this field is associated with. |
||
28 | */ |
||
29 | public $form; |
||
30 | /** |
||
31 | * @var Model the data model that this field is associated with. |
||
32 | */ |
||
33 | public $model; |
||
34 | /** |
||
35 | * @var string the model attribute that this field is associated with. |
||
36 | */ |
||
37 | public $attribute; |
||
38 | /** |
||
39 | * @var array the HTML attributes (name-value pairs) for the field container tag. |
||
40 | * The values will be HTML-encoded using [[Html::encode()]]. |
||
41 | * If a value is `null`, the corresponding attribute will not be rendered. |
||
42 | * The following special options are recognized: |
||
43 | * |
||
44 | * - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag. |
||
45 | * See also [[\yii\helpers\Html::tag()]]. |
||
46 | * |
||
47 | * If you set a custom `id` for the container element, you may need to adjust the [[$selectors]] accordingly. |
||
48 | * |
||
49 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
50 | */ |
||
51 | public $options = ['class' => 'form-group']; |
||
52 | /** |
||
53 | * @var string the template that is used to arrange the label, the input field, the error message and the hint text. |
||
54 | * The following tokens will be replaced when [[render()]] is called: `{label}`, `{input}`, `{error}` and `{hint}`. |
||
55 | */ |
||
56 | public $template = "{label}\n{input}\n{hint}\n{error}"; |
||
57 | /** |
||
58 | * @var array the default options for the input tags. The parameter passed to individual input methods |
||
59 | * (e.g. [[textInput()]]) will be merged with this property when rendering the input tag. |
||
60 | * |
||
61 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
62 | * |
||
63 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
64 | */ |
||
65 | public $inputOptions = ['class' => 'form-control']; |
||
66 | /** |
||
67 | * @var array the default options for the error tags. The parameter passed to [[error()]] will be |
||
68 | * merged with this property when rendering the error tag. |
||
69 | * The following special options are recognized: |
||
70 | * |
||
71 | * - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag. |
||
72 | * See also [[\yii\helpers\Html::tag()]]. |
||
73 | * - `encode`: whether to encode the error output. Defaults to `true`. |
||
74 | * |
||
75 | * If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly. |
||
76 | * |
||
77 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
78 | */ |
||
79 | public $errorOptions = ['class' => 'help-block']; |
||
80 | /** |
||
81 | * @var array the default options for the label tags. The parameter passed to [[label()]] will be |
||
82 | * merged with this property when rendering the label tag. |
||
83 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
84 | */ |
||
85 | public $labelOptions = ['class' => 'control-label']; |
||
86 | /** |
||
87 | * @var array the default options for the hint tags. The parameter passed to [[hint()]] will be |
||
88 | * merged with this property when rendering the hint tag. |
||
89 | * The following special options are recognized: |
||
90 | * |
||
91 | * - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag. |
||
92 | * See also [[\yii\helpers\Html::tag()]]. |
||
93 | * |
||
94 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
95 | */ |
||
96 | public $hintOptions = ['class' => 'hint-block']; |
||
97 | /** |
||
98 | * @var boolean whether to enable client-side data validation. |
||
99 | * If not set, it will take the value of [[ActiveForm::enableClientValidation]]. |
||
100 | */ |
||
101 | public $enableClientValidation; |
||
102 | /** |
||
103 | * @var boolean whether to enable AJAX-based data validation. |
||
104 | * If not set, it will take the value of [[ActiveForm::enableAjaxValidation]]. |
||
105 | */ |
||
106 | public $enableAjaxValidation; |
||
107 | /** |
||
108 | * @var boolean whether to perform validation when the value of the input field is changed. |
||
109 | * If not set, it will take the value of [[ActiveForm::validateOnChange]]. |
||
110 | */ |
||
111 | public $validateOnChange; |
||
112 | /** |
||
113 | * @var boolean whether to perform validation when the input field loses focus. |
||
114 | * If not set, it will take the value of [[ActiveForm::validateOnBlur]]. |
||
115 | */ |
||
116 | public $validateOnBlur; |
||
117 | /** |
||
118 | * @var boolean whether to perform validation while the user is typing in the input field. |
||
119 | * If not set, it will take the value of [[ActiveForm::validateOnType]]. |
||
120 | * @see validationDelay |
||
121 | */ |
||
122 | public $validateOnType; |
||
123 | /** |
||
124 | * @var integer number of milliseconds that the validation should be delayed when the user types in the field |
||
125 | * and [[validateOnType]] is set `true`. |
||
126 | * If not set, it will take the value of [[ActiveForm::validationDelay]]. |
||
127 | */ |
||
128 | public $validationDelay; |
||
129 | /** |
||
130 | * @var array the jQuery selectors for selecting the container, input and error tags. |
||
131 | * The array keys should be `container`, `input`, and/or `error`, and the array values |
||
132 | * are the corresponding selectors. For example, `['input' => '#my-input']`. |
||
133 | * |
||
134 | * The container selector is used under the context of the form, while the input and the error |
||
135 | * selectors are used under the context of the container. |
||
136 | * |
||
137 | * You normally do not need to set this property as the default selectors should work well for most cases. |
||
138 | */ |
||
139 | public $selectors = []; |
||
140 | /** |
||
141 | * @var array different parts of the field (e.g. input, label). This will be used together with |
||
142 | * [[template]] to generate the final field HTML code. The keys are the token names in [[template]], |
||
143 | * while the values are the corresponding HTML code. Valid tokens include `{input}`, `{label}` and `{error}`. |
||
144 | * Note that you normally don't need to access this property directly as |
||
145 | * it is maintained by various methods of this class. |
||
146 | */ |
||
147 | public $parts = []; |
||
148 | |||
149 | /** |
||
150 | * @var string this property holds a custom input id if it was set using [[inputOptions]] or in one of the |
||
151 | * `$options` parameters of the `input*` methods. |
||
152 | */ |
||
153 | private $_inputId; |
||
154 | |||
155 | /** |
||
156 | * @var bool if "for" field label attribute should be skipped. |
||
157 | */ |
||
158 | private $_skipLabelFor = false; |
||
159 | |||
160 | |||
161 | /** |
||
162 | * PHP magic method that returns the string representation of this object. |
||
163 | * @return string the string representation of this object. |
||
164 | */ |
||
165 | 4 | public function __toString() |
|
176 | |||
177 | /** |
||
178 | * Renders the whole field. |
||
179 | * This method will generate the label, error tag, input tag and hint tag (if any), and |
||
180 | * assemble them into HTML according to [[template]]. |
||
181 | * @param string|callable $content the content within the field container. |
||
182 | * If `null` (not set), the default methods will be called to generate the label, error tag and input tag, |
||
183 | * and use them as the content. |
||
184 | * If a callable, it will be called to generate the content. The signature of the callable should be: |
||
185 | * |
||
186 | * ```php |
||
187 | * function ($field) { |
||
188 | * return $html; |
||
189 | * } |
||
190 | * ``` |
||
191 | * |
||
192 | * @return string the rendering result. |
||
193 | */ |
||
194 | 6 | public function render($content = null) |
|
216 | |||
217 | /** |
||
218 | * Renders the opening tag of the field container. |
||
219 | * @return string the rendering result. |
||
220 | */ |
||
221 | 10 | public function begin() |
|
246 | |||
247 | /** |
||
248 | * Renders the closing tag of the field container. |
||
249 | * @return string the rendering result. |
||
250 | */ |
||
251 | 7 | public function end() |
|
255 | |||
256 | /** |
||
257 | * Generates a label tag for [[attribute]]. |
||
258 | * @param null|string|false $label the label to use. If `null`, the label will be generated via [[Model::getAttributeLabel()]]. |
||
259 | * If `false`, the generated field will not contain the label part. |
||
260 | * Note that this will NOT be [[Html::encode()|encoded]]. |
||
261 | * @param null|array $options the tag options in terms of name-value pairs. It will be merged with [[labelOptions]]. |
||
262 | * The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded |
||
263 | * using [[Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered. |
||
264 | * @return $this the field object itself. |
||
265 | */ |
||
266 | 8 | public function label($label = null, $options = []) |
|
267 | { |
||
268 | 8 | if ($label === false) { |
|
269 | 2 | $this->parts['{label}'] = ''; |
|
270 | 2 | return $this; |
|
271 | } |
||
272 | |||
273 | 8 | $options = array_merge($this->labelOptions, $options); |
|
274 | 8 | if ($label !== null) { |
|
275 | 2 | $options['label'] = $label; |
|
276 | 2 | } |
|
277 | |||
278 | 8 | if ($this->_skipLabelFor) { |
|
279 | $options['for'] = null; |
||
280 | } |
||
281 | |||
282 | 8 | $this->parts['{label}'] = Html::activeLabel($this->model, $this->attribute, $options); |
|
283 | |||
284 | 8 | return $this; |
|
285 | } |
||
286 | |||
287 | /** |
||
288 | * Generates a tag that contains the first validation error of [[attribute]]. |
||
289 | * Note that even if there is no validation error, this method will still return an empty error tag. |
||
290 | * @param array|false $options the tag options in terms of name-value pairs. It will be merged with [[errorOptions]]. |
||
291 | * The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded |
||
292 | * using [[Html::encode()]]. If this parameter is `false`, no error tag will be rendered. |
||
293 | * |
||
294 | * The following options are specially handled: |
||
295 | * |
||
296 | * - `tag`: this specifies the tag name. If not set, `div` will be used. |
||
297 | * See also [[\yii\helpers\Html::tag()]]. |
||
298 | * |
||
299 | * If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly. |
||
300 | * @see $errorOptions |
||
301 | * @return $this the field object itself. |
||
302 | */ |
||
303 | 6 | public function error($options = []) |
|
314 | |||
315 | /** |
||
316 | * Renders the hint tag. |
||
317 | * @param string|bool $content the hint content. |
||
318 | * If `null`, the hint will be generated via [[Model::getAttributeHint()]]. |
||
319 | * If `false`, the generated field will not contain the hint part. |
||
320 | * Note that this will NOT be [[Html::encode()|encoded]]. |
||
321 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
322 | * the attributes of the hint tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
323 | * |
||
324 | * The following options are specially handled: |
||
325 | * |
||
326 | * - `tag`: this specifies the tag name. If not set, `div` will be used. |
||
327 | * See also [[\yii\helpers\Html::tag()]]. |
||
328 | * |
||
329 | * @return $this the field object itself. |
||
330 | */ |
||
331 | 9 | public function hint($content = null, $options = []) |
|
332 | { |
||
333 | 9 | if ($content === false) { |
|
334 | 1 | $this->parts['{hint}'] = ''; |
|
335 | 1 | return $this; |
|
336 | } |
||
337 | |||
338 | 8 | $options = array_merge($this->hintOptions, $options); |
|
339 | 8 | if ($content !== null) { |
|
340 | 1 | $options['hint'] = $content; |
|
341 | 1 | } |
|
342 | 8 | $this->parts['{hint}'] = Html::activeHint($this->model, $this->attribute, $options); |
|
343 | |||
344 | 8 | return $this; |
|
345 | } |
||
346 | |||
347 | /** |
||
348 | * Renders an input tag. |
||
349 | * @param string $type the input type (e.g. `text`, `password`) |
||
350 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
351 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
352 | * |
||
353 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
354 | * |
||
355 | * @return $this the field object itself. |
||
356 | */ |
||
357 | 2 | public function input($type, $options = []) |
|
365 | |||
366 | /** |
||
367 | * Renders a text input. |
||
368 | * This method will generate the `name` and `value` tag attributes automatically for the model attribute |
||
369 | * unless they are explicitly specified in `$options`. |
||
370 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
371 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
372 | * |
||
373 | * The following special options are recognized: |
||
374 | * |
||
375 | * - `maxlength`: integer|boolean, when `maxlength` is set `true` and the model attribute is validated |
||
376 | * by a string validator, the `maxlength` option will take the value of [[\yii\validators\StringValidator::max]]. |
||
377 | * This is available since version 2.0.3. |
||
378 | * |
||
379 | * Note that if you set a custom `id` for the input element, you may need to adjust the value of [[selectors]] accordingly. |
||
380 | * |
||
381 | * @return $this the field object itself. |
||
382 | */ |
||
383 | 6 | public function textInput($options = []) |
|
391 | |||
392 | /** |
||
393 | * Renders a hidden input. |
||
394 | * |
||
395 | * Note that this method is provided for completeness. In most cases because you do not need |
||
396 | * to validate a hidden input, you should not need to use this method. Instead, you should |
||
397 | * use [[\yii\helpers\Html::activeHiddenInput()]]. |
||
398 | * |
||
399 | * This method will generate the `name` and `value` tag attributes automatically for the model attribute |
||
400 | * unless they are explicitly specified in `$options`. |
||
401 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
402 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
403 | * |
||
404 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
405 | * |
||
406 | * @return $this the field object itself. |
||
407 | */ |
||
408 | 1 | public function hiddenInput($options = []) |
|
416 | |||
417 | /** |
||
418 | * Renders a password input. |
||
419 | * This method will generate the `name` and `value` tag attributes automatically for the model attribute |
||
420 | * unless they are explicitly specified in `$options`. |
||
421 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
422 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
423 | * |
||
424 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
425 | * |
||
426 | * @return $this the field object itself. |
||
427 | */ |
||
428 | public function passwordInput($options = []) |
||
436 | |||
437 | /** |
||
438 | * Renders a file input. |
||
439 | * This method will generate the `name` and `value` tag attributes automatically for the model attribute |
||
440 | * unless they are explicitly specified in `$options`. |
||
441 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
442 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
443 | * |
||
444 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
445 | * |
||
446 | * @return $this the field object itself. |
||
447 | */ |
||
448 | 1 | public function fileInput($options = []) |
|
463 | |||
464 | /** |
||
465 | * Renders a text area. |
||
466 | * The model attribute value will be used as the content in the textarea. |
||
467 | * @param array $options the tag options in terms of name-value pairs. These will be rendered as |
||
468 | * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. |
||
469 | * |
||
470 | * If you set a custom `id` for the textarea element, you may need to adjust the [[$selectors]] accordingly. |
||
471 | * |
||
472 | * @return $this the field object itself. |
||
473 | */ |
||
474 | public function textarea($options = []) |
||
482 | |||
483 | /** |
||
484 | * Renders a radio button. |
||
485 | * This method will generate the `checked` tag attribute according to the model attribute value. |
||
486 | * @param array $options the tag options in terms of name-value pairs. The following options are specially handled: |
||
487 | * |
||
488 | * - `uncheck`: string, the value associated with the uncheck state of the radio button. If not set, |
||
489 | * it will take the default value `0`. This method will render a hidden input so that if the radio button |
||
490 | * is not checked and is submitted, the value of this attribute will still be submitted to the server |
||
491 | * via the hidden input. If you do not want any hidden input, you should explicitly set this option as `null`. |
||
492 | * - `label`: string, a label displayed next to the radio button. It will NOT be HTML-encoded. Therefore you can pass |
||
493 | * in HTML code such as an image tag. If this is coming from end users, you should [[Html::encode()|encode]] it to prevent XSS attacks. |
||
494 | * When this option is specified, the radio button will be enclosed by a label tag. If you do not want any label, you should |
||
495 | * explicitly set this option as `null`. |
||
496 | * - `labelOptions`: array, the HTML attributes for the label tag. This is only used when the `label` option is specified. |
||
497 | * |
||
498 | * The rest of the options will be rendered as the attributes of the resulting tag. The values will |
||
499 | * be HTML-encoded using [[Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered. |
||
500 | * |
||
501 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
502 | * |
||
503 | * @param boolean $enclosedByLabel whether to enclose the radio within the label. |
||
504 | * If `true`, the method will still use [[template]] to layout the radio button and the error message |
||
505 | * except that the radio is enclosed by the label tag. |
||
506 | * @return $this the field object itself. |
||
507 | */ |
||
508 | public function radio($options = [], $enclosedByLabel = true) |
||
528 | |||
529 | /** |
||
530 | * Renders a checkbox. |
||
531 | * This method will generate the `checked` tag attribute according to the model attribute value. |
||
532 | * @param array $options the tag options in terms of name-value pairs. The following options are specially handled: |
||
533 | * |
||
534 | * - `uncheck`: string, the value associated with the uncheck state of the radio button. If not set, |
||
535 | * it will take the default value `0`. This method will render a hidden input so that if the radio button |
||
536 | * is not checked and is submitted, the value of this attribute will still be submitted to the server |
||
537 | * via the hidden input. If you do not want any hidden input, you should explicitly set this option as `null`. |
||
538 | * - `label`: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass |
||
539 | * in HTML code such as an image tag. If this is coming from end users, you should [[Html::encode()|encode]] it to prevent XSS attacks. |
||
540 | * When this option is specified, the checkbox will be enclosed by a label tag. If you do not want any label, you should |
||
541 | * explicitly set this option as `null`. |
||
542 | * - `labelOptions`: array, the HTML attributes for the label tag. This is only used when the `label` option is specified. |
||
543 | * |
||
544 | * The rest of the options will be rendered as the attributes of the resulting tag. The values will |
||
545 | * be HTML-encoded using [[Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered. |
||
546 | * |
||
547 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
548 | * |
||
549 | * @param boolean $enclosedByLabel whether to enclose the checkbox within the label. |
||
550 | * If `true`, the method will still use [[template]] to layout the checkbox and the error message |
||
551 | * except that the checkbox is enclosed by the label tag. |
||
552 | * @return $this the field object itself. |
||
553 | */ |
||
554 | public function checkbox($options = [], $enclosedByLabel = true) |
||
574 | |||
575 | /** |
||
576 | * Renders a drop-down list. |
||
577 | * The selection of the drop-down list is taken from the value of the model attribute. |
||
578 | * @param array $items the option data items. The array keys are option values, and the array values |
||
579 | * are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). |
||
580 | * For each sub-array, an option group will be generated whose label is the key associated with the sub-array. |
||
581 | * If you have a list of data models, you may convert them into the format described above using |
||
582 | * [[ArrayHelper::map()]]. |
||
583 | * |
||
584 | * Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in |
||
585 | * the labels will also be HTML-encoded. |
||
586 | * @param array $options the tag options in terms of name-value pairs. |
||
587 | * |
||
588 | * For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeDropDownList()]]. |
||
589 | * |
||
590 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
591 | * |
||
592 | * @return $this the field object itself. |
||
593 | */ |
||
594 | public function dropDownList($items, $options = []) |
||
602 | |||
603 | /** |
||
604 | * Renders a list box. |
||
605 | * The selection of the list box is taken from the value of the model attribute. |
||
606 | * @param array $items the option data items. The array keys are option values, and the array values |
||
607 | * are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). |
||
608 | * For each sub-array, an option group will be generated whose label is the key associated with the sub-array. |
||
609 | * If you have a list of data models, you may convert them into the format described above using |
||
610 | * [[\yii\helpers\ArrayHelper::map()]]. |
||
611 | * |
||
612 | * Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in |
||
613 | * the labels will also be HTML-encoded. |
||
614 | * @param array $options the tag options in terms of name-value pairs. |
||
615 | * |
||
616 | * For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeListBox()]]. |
||
617 | * |
||
618 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
619 | * |
||
620 | * @return $this the field object itself. |
||
621 | */ |
||
622 | 2 | public function listBox($items, $options = []) |
|
630 | |||
631 | /** |
||
632 | * Renders a list of checkboxes. |
||
633 | * A checkbox list allows multiple selection, like [[listBox()]]. |
||
634 | * As a result, the corresponding submitted value is an array. |
||
635 | * The selection of the checkbox list is taken from the value of the model attribute. |
||
636 | * @param array $items the data item used to generate the checkboxes. |
||
637 | * The array values are the labels, while the array keys are the corresponding checkbox values. |
||
638 | * @param array $options options (name => config) for the checkbox list. |
||
639 | * For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeCheckboxList()]]. |
||
640 | * @return $this the field object itself. |
||
641 | */ |
||
642 | public function checkboxList($items, $options = []) |
||
650 | |||
651 | /** |
||
652 | * Renders a list of radio buttons. |
||
653 | * A radio button list is like a checkbox list, except that it only allows single selection. |
||
654 | * The selection of the radio buttons is taken from the value of the model attribute. |
||
655 | * @param array $items the data item used to generate the radio buttons. |
||
656 | * The array values are the labels, while the array keys are the corresponding radio values. |
||
657 | * @param array $options options (name => config) for the radio button list. |
||
658 | * For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeRadioList()]]. |
||
659 | * @return $this the field object itself. |
||
660 | */ |
||
661 | public function radioList($items, $options = []) |
||
669 | |||
670 | /** |
||
671 | * Renders a widget as the input of the field. |
||
672 | * |
||
673 | * Note that the widget must have both `model` and `attribute` properties. They will |
||
674 | * be initialized with [[model]] and [[attribute]] of this field, respectively. |
||
675 | * |
||
676 | * If you want to use a widget that does not have `model` and `attribute` properties, |
||
677 | * please use [[render()]] instead. |
||
678 | * |
||
679 | * For example to use the [[MaskedInput]] widget to get some date input, you can use |
||
680 | * the following code, assuming that `$form` is your [[ActiveForm]] instance: |
||
681 | * |
||
682 | * ```php |
||
683 | * $form->field($model, 'date')->widget(\yii\widgets\MaskedInput::class, [ |
||
684 | * 'mask' => '99/99/9999', |
||
685 | * ]); |
||
686 | * ``` |
||
687 | * |
||
688 | * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. |
||
689 | * |
||
690 | * @param string $class the widget class name. |
||
691 | * @param array $config name-value pairs that will be used to initialize the widget. |
||
692 | * @return $this the field object itself. |
||
693 | */ |
||
694 | public function widget($class, $config = []) |
||
707 | |||
708 | /** |
||
709 | * Adjusts the `for` attribute for the label based on the input options. |
||
710 | * @param array $options the input options. |
||
711 | */ |
||
712 | 12 | protected function adjustLabelFor($options) |
|
722 | |||
723 | /** |
||
724 | * Returns the JS options for the field. |
||
725 | * @return array the JS options. |
||
726 | */ |
||
727 | 5 | protected function getClientOptions() |
|
793 | |||
794 | /** |
||
795 | * Returns the HTML `id` of the input element of this form field. |
||
796 | * @return string the input id. |
||
797 | * @since 2.0.7 |
||
798 | */ |
||
799 | 13 | protected function getInputId() |
|
803 | } |
||
804 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: