mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #10631: Splitted gettng label and rendering cell in yii\grid\DataColumn::renderHeaderCellContent()
to make code simpler
This commit is contained in:

committed by
Alexander Makarov

parent
6dd017c2a3
commit
b5b55ad302
@ -124,7 +124,17 @@ class Column extends Object
|
||||
*/
|
||||
protected function renderHeaderCellContent()
|
||||
{
|
||||
return trim($this->header) !== '' ? $this->header : $this->grid->emptyCell;
|
||||
return trim($this->header) !== '' ? $this->header : $this->getHeaderCellLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns header cell label.
|
||||
* This method may be overridden to customize the label of the header cell.
|
||||
* @return string label
|
||||
*/
|
||||
protected function getHeaderCellLabel()
|
||||
{
|
||||
return $this->grid->emptyCell;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,6 +117,21 @@ class DataColumn extends Column
|
||||
return parent::renderHeaderCellContent();
|
||||
}
|
||||
|
||||
$label = $this->getHeaderCellLabel();
|
||||
|
||||
if ($this->attribute !== null && $this->enableSorting &&
|
||||
($sort = $this->grid->dataProvider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
|
||||
return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => ($this->encodeLabel ? Html::encode($label) : $label)]));
|
||||
} else {
|
||||
return $this->encodeLabel ? Html::encode() : $label;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getHeaderCellLabel()
|
||||
{
|
||||
$provider = $this->grid->dataProvider;
|
||||
|
||||
if ($this->label === null) {
|
||||
@ -137,12 +152,7 @@ class DataColumn extends Column
|
||||
$label = $this->label;
|
||||
}
|
||||
|
||||
if ($this->attribute !== null && $this->enableSorting &&
|
||||
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
|
||||
return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => $this->encodeLabel ? Html::encode($label) : $label]));
|
||||
} else {
|
||||
return $this->encodeLabel ? Html::encode($label) : $label;
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user