|
|
|
@ -125,9 +125,10 @@ 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, desc and label. |
|
|
|
|
* to configure every attribute. Each attribute must include these elements: asc and desc. |
|
|
|
|
*/ |
|
|
|
|
public $attributes = array(); |
|
|
|
|
/** |
|
|
|
@ -195,13 +196,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; |
|
|
|
@ -287,7 +286,11 @@ 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 array $options additional HTML attributes for the hyperlink tag |
|
|
|
|
* @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. |
|
|
|
|
* Note that it will not be HTML-encoded. |
|
|
|
|
* @return string the generated hyperlink |
|
|
|
|
* @throws InvalidConfigException if the attribute is unknown |
|
|
|
|
*/ |
|
|
|
@ -304,7 +307,18 @@ 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($options['label'])) { |
|
|
|
|
$label = $options['label']; |
|
|
|
|
unset($options['label']); |
|
|
|
|
} else { |
|
|
|
|
if (isset($this->attributes[$attribute]['label'])) { |
|
|
|
|
$label = $this->attributes[$attribute]['label']; |
|
|
|
|
} else { |
|
|
|
|
$label = Inflector::camel2words($attribute); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return Html::a($label, $url, $options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|