Skip to content

Commit

Permalink
label render fix
Browse files Browse the repository at this point in the history
  • Loading branch information
worstinme committed Jan 15, 2019
1 parent b8b2589 commit 7a0a00f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 19 additions & 6 deletions ActiveField.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public function render($content = null)
{
if ($content === null) {

if (!isset($this->parts['{input}'])) {
$this->textInput();
}
if (!isset($this->parts['{error}'])) {
$this->error();
}
if (!isset($this->parts['{hint}'])) {
$this->hint(null);
}

if (strpos($this->template,'{label}') !== false) {
if (strpos($this->template,'{info}') === false) {
$this->template = str_replace('{label}','{beginLabel}{labelTitle}{info}{endLabel}', $this->template);
Expand Down Expand Up @@ -165,9 +175,13 @@ public function render($content = null)
$this->parts['{endLabel}'] = '';
}

$content = strtr($this->template, $this->parts);

} elseif (!is_string($content)) {
$content = call_user_func($content, $this);
}

return parent::render($content);
return $this->begin() . "\n" . $content . "\n" . $this->end();
}

/**
Expand All @@ -181,17 +195,16 @@ public function label($label = null, $options = [])
}

$options = array_merge($this->labelOptions, $options);
if ($label !== null) {
$options['label'] = $label;

if ($label === null) {
$attribute = Html::getAttributeName($this->attribute);
$label = Html::encode($this->model->getAttributeLabel($attribute));
}

if ($this->_skipLabelFor) {
$options['for'] = null;
}

$attribute = Html::getAttributeName($this->attribute);
$label = Html::encode($this->model->getAttributeLabel($attribute));

$this->parts['{beginLabel}'] = Html::beginTag('label', $options);
$this->parts['{endLabel}'] = Html::endTag('label');
$this->parts['{labelTitle}'] = $label;
Expand Down
8 changes: 8 additions & 0 deletions ActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,12 @@ public function init()

parent::init();
}

/**
* @return ActiveField
*/
public function field($model, $attribute, $options = [])
{
return parent::field($model, $attribute, $options);
}
}

0 comments on commit 7a0a00f

Please sign in to comment.