public function toString($HighlightRoute = '')
{
if ($HighlightRoute == '') {
$HighlightRoute = $this->_HighlightRoute;
}
if ($HighlightRoute == '') {
$HighlightRoute = Gdn_Url::Request();
}
$HighlightUrl = url($HighlightRoute);
// Apply a sort to the items if given.
if (is_array($this->Sort)) {
$Sort = array_flip($this->Sort);
foreach ($this->Items as $Group => &$Item) {
if (isset($Sort[$Group])) {
$Item['Sort'] = $Sort[$Group];
} else {
$Item['_Sort'] += count($Sort);
}
foreach ($Item['Links'] as $Url => &$Link) {
if (isset($Sort[$Url])) {
$Link['Sort'] = $Sort[$Url];
} elseif (isset($Sort[$Link['Text']])) {
$Link['Sort'] = $Sort[$Link['Text']];
} else {
$Link['_Sort'] += count($Sort);
}
}
}
}
// Sort the groups.
$this->_Compare($this->Items);
uasort($this->Items, array($this, '_Compare'));
// Sort the items within the groups.
foreach ($this->Items as &$Item) {
$this->_Compare($Item['Links']);
uasort($Item['Links'], array($this, '_Compare'));
// Highlight the group.
if (val('Url', $Item) && url($Item['Url']) == $HighlightUrl) {
$Item['Attributes']['class'] = ConcatSep(' ', val('class', $Item['Attributes']), 'Active');
}
// Hightlight the correct item in the group.
foreach ($Item['Links'] as &$Link) {
if (val('Url', $Link) && url($Link['Url']) == $HighlightUrl) {
$Link['Attributes']['class'] = ConcatSep(' ', val('class', $Link['Attributes']), 'Active');
$Item['Attributes']['class'] = ConcatSep(' ', val('class', $Item['Attributes']), 'Active');
}
}
}
return parent::ToString();
}