Commit 39c002e8 by Carsten Brandt

Refactored DataColumn::renderHeaderCellContent()

parent 155749e1
...@@ -72,36 +72,36 @@ class DataColumn extends Column ...@@ -72,36 +72,36 @@ class DataColumn extends Column
protected function renderHeaderCellContent() protected function renderHeaderCellContent()
{ {
if ($this->header === null) { if ($this->header !== null || $this->label === null && $this->attribute === null) {
$provider = $this->grid->dataProvider; return parent::renderHeaderCellContent();
}
$provider = $this->grid->dataProvider;
if ($this->label === null) { if ($this->label === null) {
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) {
/** @var Model $model */
$model = new $provider->query->modelClass;
$label = $model->getAttributeLabel($this->attribute);
} else {
$models = $provider->getModels();
if (($model = reset($models)) instanceof Model) {
/** @var Model $model */ /** @var Model $model */
$model = new $provider->query->modelClass;
$label = $model->getAttributeLabel($this->attribute); $label = $model->getAttributeLabel($this->attribute);
} else { } else {
$models = $provider->getModels(); $label = Inflector::camel2words($this->attribute);
if (($model = reset($models)) instanceof Model) {
/** @var Model $model */
$label = $model->getAttributeLabel($this->attribute);
} else {
$label = Inflector::camel2words($this->attribute);
}
} }
} else {
$label = $this->label;
} }
} else {
$label = $this->label;
}
if ($this->attribute !== null && $this->enableSorting && if ($this->attribute !== null && $this->enableSorting &&
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions);
} else {
return Html::encode($label);
}
} else { } else {
return parent::renderHeaderCellContent(); return Html::encode($label);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment