label() public method

Generates a label tag for [[attribute]].
public label ( null | string | false $label = null, null | array $options = [] )
$label null | string | false 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]].
$options null | array 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.
    public function testError()
    {
        $expectedValue = '<label class="control-label" for="dynamicmodel-attributename">Attribute Name</label>';
        $this->activeField->label();
        $this->assertEquals($expectedValue, $this->activeField->parts['{label}']);
        // label = false
        $expectedValue = '';
        $this->activeField->label(false);
        $this->assertEquals($expectedValue, $this->activeField->parts['{label}']);
        // $label = 'Label Name'
        $label = 'Label Name';
        $expectedValue = <<<EOT
<label class="control-label" for="dynamicmodel-attributename">{$label}</label>
EOT;
        $this->activeField->label($label);
        $this->assertEquals($expectedValue, $this->activeField->parts['{label}']);
    }
 /**
  * @inheritdoc
  */
 public function label($label = null, $options = [])
 {
     if (is_bool($label)) {
         $this->enableLabel = $label;
         if ($label === false && $this->form->layout === 'horizontal') {
             Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);
         }
     } else {
         $this->enableLabel = true;
         $this->renderLabelParts($label, $options);
         parent::label($label, $options);
     }
     return $this;
 }
 /**
  * @inheritdoc
  */
 public function label($label = null, $options = [])
 {
     $hasLabels = $this->hasLabels();
     $processLabels = $label !== false && $this->_isHintSpecial && $hasLabels !== false && $hasLabels !== ActiveForm::SCREEN_READER && ($this->getHintData('onLabelClick') || $this->getHintData('onLabelHover'));
     if ($processLabels) {
         if ($label === null) {
             $label = $this->model->getAttributeLabel($this->attribute);
         }
         $opts = ['class' => 'kv-type-label'];
         Html::addCssClass($opts, $this->getHintIconCss('Label'));
         $label = Html::tag('span', $label, $opts);
         if ($this->getHintData('showIcon') && !$this->getHintData('iconBesideInput')) {
             $label = strtr($this->getHintData('labelTemplate'), ['{label}' => $label, '{help}' => $this->getHintIcon()]);
         }
     }
     if (strpos($this->template, '{beginLabel}') !== false) {
         $this->renderLabelParts($label, $options);
     }
     return parent::label($label, $options);
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function label($label = null, $options = [])
 {
     if (is_bool($label)) {
         $this->enableLabel = $label;
         if ($label === false && $this->form->layout === 'horizontal') {
             Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);
         }
     } else {
         $this->enableLabel = true;
         $this->renderLabelParts($label, $options);
         if (isset($this->parts['{help}'])) {
             if ($label !== null) {
                 $options['label'] = $label;
             } else {
                 $attribute = Html::getAttributeName($this->attribute);
                 $options['label'] = Html::encode($this->model->getAttributeLabel($attribute));
             }
             $options['label'] .= ' ' . $this->parts['{help}'];
         }
         parent::label($label, $options);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * @inherit doc
  */
 public function label($label = null, $options = [])
 {
     if ($label === false) {
         $this->showLabels = false;
     }
     return parent::label($label, $options);
 }
Beispiel #6
0
 /**
  *
  * Стандартная обработка поля формы.
  *
  * @param \yii\widgets\ActiveField $field
  * @return \yii\widgets\ActiveField
  */
 public function postFieldRender(\yii\widgets\ActiveField $field)
 {
     if ($this->property->hint) {
         $field->hint((string) $this->property->hint);
     }
     if ($this->property->name) {
         $field->label($this->property->name);
     } else {
         $field->label(false);
     }
     return $field;
 }
Beispiel #7
0
 /**
  * @inheritdoc
  */
 public function label($label = null, $options = [])
 {
     if (is_bool($label)) {
         $this->enableLabel = $label;
     } else {
         $this->enableLabel = true;
         $this->renderLabelParts($label, $options);
         parent::label($label, $options);
     }
     return $this;
 }