From 53b4ed3d7f9b2611ce2d572adccaf2a01d771a05 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 18:02:44 +0200 Subject: [PATCH] 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); }