From 713a987a9d803ea9e676026321f7428bdd904dbd Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 00:00:14 +0200 Subject: [PATCH 01/10] auto fill sorting colums in ActiveDataProvider if none are configured --- framework/yii/data/ActiveDataProvider.php | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/framework/yii/data/ActiveDataProvider.php b/framework/yii/data/ActiveDataProvider.php index 6dfc9ed..539d00a 100644 --- a/framework/yii/data/ActiveDataProvider.php +++ b/framework/yii/data/ActiveDataProvider.php @@ -9,6 +9,8 @@ namespace yii\data; use Yii; use yii\base\InvalidConfigException; +use yii\base\InvalidParamException; +use yii\base\Model; use yii\db\Query; use yii\db\ActiveQuery; use yii\db\Connection; @@ -214,4 +216,34 @@ class ActiveDataProvider extends DataProvider $this->_totalCount = null; $this->_keys = null; } + + /** + * Sets the sort definition for this data provider. + * @param array|Sort|boolean $value the sort definition to be used by this data provider. + * This can be one of the following: + * + * - a configuration array for creating the sort definition object. The "class" element defaults + * to 'yii\data\Sort' + * - an instance of [[Sort]] or its subclass + * - false, if sorting needs to be disabled. + * + * @throws InvalidParamException + */ + public function setSort($value) + { + parent::setSort($value); + if (($sort = $this->getSort()) !== false && empty($sort->attributes) && + $this->query instanceof ActiveQuery) { + + /** @var Model $model */ + $model = new $this->query->modelClass; + foreach($model->attributes() as $attribute) { + $sort->attributes[$attribute] = array( + 'asc' => array($attribute => Sort::ASC), + 'desc' => array($attribute => Sort::DESC), + 'label' => $model->getAttributeLabel($attribute), + ); + } + } + } } From f9fab5d40d50d8a300b5a5c83d01b4137db9212a Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 00:01:26 +0200 Subject: [PATCH 02/10] Lazy fallback of label creation for Sort class --- framework/yii/data/Sort.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/yii/data/Sort.php b/framework/yii/data/Sort.php index 73e6f1c..e638848 100644 --- a/framework/yii/data/Sort.php +++ b/framework/yii/data/Sort.php @@ -127,7 +127,7 @@ class Sort extends Object * a sort link. If not set, [[Inflector::camel2words()]] will be called to get a label. * * Note that if the Sort object is already created, you can only use the full format - * to configure every attribute. Each attribute must include these elements: asc, desc and label. + * to configure every attribute. Each attribute must include these elements: asc and desc. */ public $attributes = array(); /** @@ -195,13 +195,11 @@ class Sort extends Object $attributes[$attribute] = array( 'asc' => array($attribute => self::ASC), 'desc' => array($attribute => self::DESC), - 'label' => Inflector::camel2words($attribute), ); - } elseif (!isset($attribute['asc'], $attribute['desc'], $attribute['label'])) { + } elseif (!isset($attribute['asc'], $attribute['desc'])) { $attributes[$name] = array_merge(array( 'asc' => array($name => self::ASC), 'desc' => array($name => self::DESC), - 'label' => Inflector::camel2words($name), ), $attribute); } else { $attributes[$name] = $attribute; @@ -304,7 +302,12 @@ class Sort extends Object $url = $this->createUrl($attribute); $options['data-sort'] = $this->createSortVar($attribute); - return Html::a($this->attributes[$attribute]['label'], $url, $options); + if (isset($this->attributes[$attribute]['label'])) { + $label = $this->attributes[$attribute]['label']; + } else { + $label = Inflector::camel2words($attribute); + } + return Html::a($label, $url, $options); } /** From c5d65e09afa0f59c20068d5b3683c56449e25be1 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 00:16:12 +0200 Subject: [PATCH 03/10] Refactor DataColum to use model label for sorting link --- framework/yii/grid/DataColumn.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index d31507d..ed6e803 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -62,25 +62,33 @@ class DataColumn extends Column if ($this->attribute !== null && $this->header === null) { $provider = $this->grid->dataProvider; if ($this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { - return $sort->link($this->attribute); - } - $models = $provider->getModels(); - if (($model = reset($models)) instanceof Model) { - /** @var Model $model */ - return $model->getAttributeLabel($this->attribute); - } elseif ($provider instanceof ActiveDataProvider) { - if ($provider->query instanceof ActiveQuery) { - /** @var Model $model */ - $model = new $provider->query->modelClass; - return $model->getAttributeLabel($this->attribute); + if (!isset($sort->attributes[$this->attribute]['label'])) { + $sort->attributes[$this->attribute]['label'] = $this->getHeaderLabel(); } + return $sort->link($this->attribute); } - return Inflector::camel2words($this->attribute); + return $this->getHeaderLabel(); } else { return parent::renderHeaderCellContent(); } } + protected function getHeaderLabel() + { + $provider = $this->grid->dataProvider; + if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { + /** @var Model $model */ + $model = new $provider->query->modelClass; + return $model->getAttributeLabel($this->attribute); + } + $models = $provider->getModels(); + if (($model = reset($models)) instanceof Model) { + /** @var Model $model */ + return $model->getAttributeLabel($this->attribute); + } + return Inflector::camel2words($this->attribute); + } + protected function renderFilterCellContent() { if (is_string($this->filter)) { From 381216595d9cd8caf6d6ff8979ceae8ec86a1758 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 00:37:29 +0200 Subject: [PATCH 04/10] DataColumn: Allow setting label of sort link via short syntax attribute:type:Header should also affect sort link --- framework/yii/grid/DataColumn.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index ed6e803..e1913c3 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -59,14 +59,16 @@ class DataColumn extends Column protected function renderHeaderCellContent() { - if ($this->attribute !== null && $this->header === null) { - $provider = $this->grid->dataProvider; - if ($this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { - if (!isset($sort->attributes[$this->attribute]['label'])) { - $sort->attributes[$this->attribute]['label'] = $this->getHeaderLabel(); - } - return $sort->link($this->attribute); + $provider = $this->grid->dataProvider; + if ($this->attribute !== null && $this->enableSorting && + ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + + $label = $this->getHeaderLabel(); + if (($this->header !== null || !isset($sort->attributes[$this->attribute]['label'])) && trim($label) !== '') { + $sort->attributes[$this->attribute]['label'] = $label; } + return $sort->link($this->attribute); + } elseif ($this->header === null) { return $this->getHeaderLabel(); } else { return parent::renderHeaderCellContent(); @@ -76,6 +78,9 @@ class DataColumn extends Column protected function getHeaderLabel() { $provider = $this->grid->dataProvider; + if ($this->header !== null) { + return $this->header; + } if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { /** @var Model $model */ $model = new $provider->query->modelClass; From a2eb49cd3e48df541c2cea893967e612e355ab66 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 11:54:17 +0200 Subject: [PATCH 05/10] use `@inheritdoc` for ActiveDataProvider::setSort --- framework/yii/data/ActiveDataProvider.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/framework/yii/data/ActiveDataProvider.php b/framework/yii/data/ActiveDataProvider.php index 539d00a..0347db1 100644 --- a/framework/yii/data/ActiveDataProvider.php +++ b/framework/yii/data/ActiveDataProvider.php @@ -218,16 +218,7 @@ class ActiveDataProvider extends DataProvider } /** - * Sets the sort definition for this data provider. - * @param array|Sort|boolean $value the sort definition to be used by this data provider. - * This can be one of the following: - * - * - a configuration array for creating the sort definition object. The "class" element defaults - * to 'yii\data\Sort' - * - an instance of [[Sort]] or its subclass - * - false, if sorting needs to be disabled. - * - * @throws InvalidParamException + * @inheritdoc */ public function setSort($value) { From b147760c7bd4cecc2df3f52e94c6a409789f2241 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 14:06:48 +0200 Subject: [PATCH 06/10] added label option to Sort::link() --- framework/yii/data/Sort.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/framework/yii/data/Sort.php b/framework/yii/data/Sort.php index e638848..c2c8529 100644 --- a/framework/yii/data/Sort.php +++ b/framework/yii/data/Sort.php @@ -285,11 +285,14 @@ class Sort extends Object * Based on the sort direction, the CSS class of the generated hyperlink will be appended * with "asc" or "desc". * @param string $attribute the attribute name by which the data should be sorted by. + * @param string $label the label to be used for the generated link. + * If this is null, the label defined in [[attributes]] we be used. + * If there is no label defined, [[Inflector::camel2words()]] will be called to get a label. * @param array $options additional HTML attributes for the hyperlink tag * @return string the generated hyperlink * @throws InvalidConfigException if the attribute is unknown */ - public function link($attribute, $options = array()) + public function link($attribute, $label = null, $options = array()) { if (($direction = $this->getAttributeOrder($attribute)) !== null) { $class = $direction ? 'desc' : 'asc'; @@ -302,10 +305,13 @@ class Sort extends Object $url = $this->createUrl($attribute); $options['data-sort'] = $this->createSortVar($attribute); - if (isset($this->attributes[$attribute]['label'])) { - $label = $this->attributes[$attribute]['label']; - } else { - $label = Inflector::camel2words($attribute); + + if ($label === null) { + if (isset($this->attributes[$attribute]['label'])) { + $label = $this->attributes[$attribute]['label']; + } else { + $label = Inflector::camel2words($attribute); + } } return Html::a($label, $url, $options); } From 9847472144ee99e6a129ad6e53dfee419e6aafb8 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 15:13:16 +0200 Subject: [PATCH 07/10] introduced DataColumn::label property --- framework/yii/grid/DataColumn.php | 67 +++++++++++++++++++++++---------------- framework/yii/grid/GridView.php | 12 +++---- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index e1913c3..2b9c0be 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -28,6 +28,14 @@ class DataColumn extends Column */ public $attribute; /** + * @var string label to be displayed in the [[header|header cell]] and also to be used as the sorting + * link label when sorting is enabled for this column. + * If it is not set and the models provided by the GridViews data provider are instances + * of [[ActiveRecord]], the label will be determined via [[ActiveRecord::getAttributeLabel()]]. + * Otherwise [[yii\helpers\Inflector::camel2words]] will be used to get a label. + */ + public $label; + /** * @var \Closure an anonymous function that returns the value to be displayed for every data model. * If this is not set, `$model[$attribute]` will be used to obtain the value. */ @@ -46,6 +54,11 @@ class DataColumn extends Column */ public $enableSorting = true; /** + * @var array the HTML attributes for the link tag in the header cell + * generated by [[Sort::link]] when sorting is enabled for this column. + */ + public $sortLinkOptions = array(); + /** * @var string|array|boolean the HTML code representing a filter input (e.g. a text field, a dropdown list) * that is used for this data column. This property is effective only when [[GridView::filterModel]] is set. * @@ -59,41 +72,39 @@ class DataColumn extends Column protected function renderHeaderCellContent() { - $provider = $this->grid->dataProvider; - if ($this->attribute !== null && $this->enableSorting && - ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + if ($this->header === null) { + $provider = $this->grid->dataProvider; - $label = $this->getHeaderLabel(); - if (($this->header !== null || !isset($sort->attributes[$this->attribute]['label'])) && trim($label) !== '') { - $sort->attributes[$this->attribute]['label'] = $label; + if ($this->label === null) { + 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 */ + $label = $model->getAttributeLabel($this->attribute); + } else { + $label = Inflector::camel2words($this->attribute); + } + } + } else { + $label = $this->label; + } + + if ($this->attribute !== null && $this->enableSorting && + ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + + return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); + } else { + return Html::encode($label); } - return $sort->link($this->attribute); - } elseif ($this->header === null) { - return $this->getHeaderLabel(); } else { return parent::renderHeaderCellContent(); } } - protected function getHeaderLabel() - { - $provider = $this->grid->dataProvider; - if ($this->header !== null) { - return $this->header; - } - if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { - /** @var Model $model */ - $model = new $provider->query->modelClass; - return $model->getAttributeLabel($this->attribute); - } - $models = $provider->getModels(); - if (($model = reset($models)) instanceof Model) { - /** @var Model $model */ - return $model->getAttributeLabel($this->attribute); - } - return Inflector::camel2words($this->attribute); - } - protected function renderFilterCellContent() { if (is_string($this->filter)) { diff --git a/framework/yii/grid/GridView.php b/framework/yii/grid/GridView.php index 9490f27..60d325d 100644 --- a/framework/yii/grid/GridView.php +++ b/framework/yii/grid/GridView.php @@ -108,7 +108,7 @@ class GridView extends ListViewBase * 'class' => DataColumn::className(), * 'attribute' => 'name', * 'format' => 'text', - * 'header' => 'Name', + * 'label' => 'Name', * ), * array( * 'class' => CheckboxColumn::className(), @@ -119,9 +119,9 @@ class GridView extends ListViewBase * If a column is of class [[DataColumn]], the "class" element can be omitted. * * As a shortcut format, a string may be used to specify the configuration of a data column - * which only contains "attribute", "format", and/or "header" options: `"attribute:format:header"`. + * which only contains "attribute", "format", and/or "label" options: `"attribute:format:label"`. * For example, the above "name" column can also be specified as: `"name:text:Name"`. - * Both "format" and "header" are optional. They will take default values if absent. + * Both "format" and "label" are optional. They will take default values if absent. */ public $columns = array(); /** @@ -372,7 +372,7 @@ class GridView extends ListViewBase } /** - * Creates a [[DataColumn]] object based on a string in the format of "attribute:format:header". + * Creates a [[DataColumn]] object based on a string in the format of "attribute:format:label". * @param string $text the column specification string * @return DataColumn the column instance * @throws InvalidConfigException if the column specification is invalid @@ -380,14 +380,14 @@ class GridView extends ListViewBase protected function createDataColumn($text) { if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches)) { - throw new InvalidConfigException('The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:header'); + throw new InvalidConfigException('The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label'); } return Yii::createObject(array( 'class' => $this->dataColumnClass ?: DataColumn::className(), 'grid' => $this, 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', - 'header' => isset($matches[5]) ? $matches[5] : null, + 'label' => isset($matches[5]) ? $matches[5] : null, )); } From 155749e18d1150b7371452a22243be278dbd6388 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 15:23:22 +0200 Subject: [PATCH 08/10] typos in doc --- framework/yii/data/Sort.php | 4 ++-- framework/yii/grid/DataColumn.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/yii/data/Sort.php b/framework/yii/data/Sort.php index c2c8529..954996d 100644 --- a/framework/yii/data/Sort.php +++ b/framework/yii/data/Sort.php @@ -286,8 +286,8 @@ class Sort extends Object * with "asc" or "desc". * @param string $attribute the attribute name by which the data should be sorted by. * @param string $label the label to be used for the generated link. - * If this is null, the label defined in [[attributes]] we be used. - * If there is no label defined, [[Inflector::camel2words()]] will be called to get a label. + * If this is null, the label defined in [[attributes]] will be used. + * If no label is defined, [[yii\helpers\Inflector::camel2words()]] will be called to get a label. * @param array $options additional HTML attributes for the hyperlink tag * @return string the generated hyperlink * @throws InvalidConfigException if the attribute is unknown diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index 2b9c0be..afb2fba 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -31,8 +31,8 @@ class DataColumn extends Column * @var string label to be displayed in the [[header|header cell]] and also to be used as the sorting * link label when sorting is enabled for this column. * If it is not set and the models provided by the GridViews data provider are instances - * of [[ActiveRecord]], the label will be determined via [[ActiveRecord::getAttributeLabel()]]. - * Otherwise [[yii\helpers\Inflector::camel2words]] will be used to get a label. + * of [[yii\db\ActiveRecord]], the label will be determined using [[yii\db\ActiveRecord::getAttributeLabel()]]. + * Otherwise [[yii\helpers\Inflector::camel2words()]] will be used to get a label. */ public $label; /** From 39c002e83cc4f327577a303ba86faddd6c585144 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 15:23:49 +0200 Subject: [PATCH 09/10] Refactored DataColumn::renderHeaderCellContent() --- framework/yii/grid/DataColumn.php | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index afb2fba..82b8641 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -72,36 +72,36 @@ class DataColumn extends Column protected function renderHeaderCellContent() { - if ($this->header === null) { - $provider = $this->grid->dataProvider; + if ($this->header !== null || $this->label === null && $this->attribute === null) { + return parent::renderHeaderCellContent(); + } + + $provider = $this->grid->dataProvider; - if ($this->label === null) { - if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { + if ($this->label === null) { + 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 */ - $model = new $provider->query->modelClass; $label = $model->getAttributeLabel($this->attribute); } else { - $models = $provider->getModels(); - if (($model = reset($models)) instanceof Model) { - /** @var Model $model */ - $label = $model->getAttributeLabel($this->attribute); - } else { - $label = Inflector::camel2words($this->attribute); - } + $label = Inflector::camel2words($this->attribute); } - } else { - $label = $this->label; } + } else { + $label = $this->label; + } - if ($this->attribute !== null && $this->enableSorting && - ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + if ($this->attribute !== null && $this->enableSorting && + ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { - return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); - } else { - return Html::encode($label); - } + return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); } else { - return parent::renderHeaderCellContent(); + return Html::encode($label); } } From 53b4ed3d7f9b2611ce2d572adccaf2a01d771a05 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 18:02:44 +0200 Subject: [PATCH 10/10] Moved label for Sort::link() to html options --- framework/yii/data/Sort.php | 15 ++++++++++----- framework/yii/grid/DataColumn.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/framework/yii/data/Sort.php b/framework/yii/data/Sort.php index 954996d..d489c44 100644 --- a/framework/yii/data/Sort.php +++ b/framework/yii/data/Sort.php @@ -125,6 +125,7 @@ class Sort extends Object * if it is not currently sorted (the default value is ascending order). * - The "label" element specifies what label should be used when calling [[link()]] to create * a sort link. If not set, [[Inflector::camel2words()]] will be called to get a label. + * Note that it will not be HTML-encoded. * * Note that if the Sort object is already created, you can only use the full format * to configure every attribute. Each attribute must include these elements: asc and desc. @@ -285,14 +286,15 @@ class Sort extends Object * Based on the sort direction, the CSS class of the generated hyperlink will be appended * with "asc" or "desc". * @param string $attribute the attribute name by which the data should be sorted by. - * @param string $label the label to be used for the generated link. - * If this is null, the label defined in [[attributes]] will be used. + * @param array $options additional HTML attributes for the hyperlink tag. + * There is one special attribute `label` which will be used as the label of the hyperlink. + * If this is not set, the label defined in [[attributes]] will be used. * If no label is defined, [[yii\helpers\Inflector::camel2words()]] will be called to get a label. - * @param array $options additional HTML attributes for the hyperlink tag + * Note that it will not be HTML-encoded. * @return string the generated hyperlink * @throws InvalidConfigException if the attribute is unknown */ - public function link($attribute, $label = null, $options = array()) + public function link($attribute, $options = array()) { if (($direction = $this->getAttributeOrder($attribute)) !== null) { $class = $direction ? 'desc' : 'asc'; @@ -306,7 +308,10 @@ class Sort extends Object $url = $this->createUrl($attribute); $options['data-sort'] = $this->createSortVar($attribute); - if ($label === null) { + if (isset($options['label'])) { + $label = $options['label']; + unset($options['label']); + } else { if (isset($this->attributes[$attribute]['label'])) { $label = $this->attributes[$attribute]['label']; } else { diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index 82b8641..295dece 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -99,7 +99,7 @@ class DataColumn extends Column if ($this->attribute !== null && $this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { - return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); + return $sort->link($this->attribute, array_merge($this->sortLinkOptions, array('label' => Html::encode($label)))); } else { return Html::encode($label); }