/** * Generates a label tag for [[attribute]]. * * @param string|boolean $label the label to use. If null, the label will be generated via [[Model::getAttributeLabel()]]. * If false, the generated field will not contain the label part. * Note that this will NOT be [[Html::encode()|encoded]]. * @param array $options the tag options in terms of name-value pairs. It will be merged with [[labelOptions]]. * The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded * using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered. * @return static the field object itself */ public function label($label = null, $options = []) { if ($label === false) { $this->parts['{label}'] = ''; return $this; } $options = array_merge($this->labelOptions, $options); if ($label !== null) { $options['label'] = $label; Html::addCssClass($options, 'col-md-3'); $this->parts['{label}'] = Html::activeLabel($this->model, $this->attribute, $options); $divClassOptions = []; if (isset($this->inputOptions['col'])) { switch ($this->inputOptions['col']) { case 'small': Html::addCssClass($divClassOptions, 'col-md-3'); break; case 'big': Html::addCssClass($divClassOptions, 'col-md-6'); break; case 'large': Html::addCssClass($divClassOptions, 'col-md-9'); break; default: Html::addCssClass($divClassOptions, 'col-md-3'); break; } } else { Html::addCssClass($divClassOptions, 'col-md-6'); } unset($this->inputOptions['col']); if (isset($options['icon'])) { unset($options['class']); $options['class'] = 'form-control'; $result = $this->textInputIcon($options); $this->parts['{input}'] = Html::tag('div', Html::tag('div', $result[0], ['class' => $result[1]]), $divClassOptions); } else { $this->parts['{input}'] = Html::tag('div', Html::activeTextInput($this->model, $this->attribute, $this->inputOptions), $divClassOptions); } } else { unset($this->inputOptions['col']); $this->parts['{input}'] = Html::tag('div', Html::activeTextInput($this->model, $this->attribute, $this->inputOptions)); $this->parts['{label}'] = Html::activeLabel($this->model, $this->attribute, $options); } return $this; }