Skip to content

Commit 7258540

Browse files
author
Hubert Prein
committed
Add custom breadcrumbs
1 parent a5da7fd commit 7258540

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

services/AmNavService.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ private function _setActiveNodes($nodes)
426426

427427
foreach ($nodes as $node) {
428428
if ($node['elementType'] == 'Asset') { continue; }
429-
429+
430430
$url = ! empty($node['elementId']) ? $node['elementUrl'] : $node['url'];
431431
$url = str_replace('{siteUrl}', '', $url);
432432
$url = str_replace('__home__', '', $url);
@@ -703,10 +703,16 @@ private function _buildNavHtml($nodes, $parentId = 0, $level = 1)
703703
private function _buildBreadcrumbsHtml()
704704
{
705705
// Get active elements
706-
$activeElements = $this->_getActiveElements();
706+
$nodes = $this->_getActiveElements();
707+
708+
// Do we have custom nodes?
709+
$customNodes = $this->_getParam('customNodes', false);
710+
if ($customNodes && is_array($customNodes) && count($customNodes)) {
711+
$nodes = array_merge($nodes, $customNodes);
712+
}
707713

708714
// Create breadcrumbs
709-
$length = count($activeElements);
715+
$length = count($nodes);
710716
$breadcrumbs = "\n" . sprintf('<%1$s%2$s%3$s xmlns:v="http://rdf.data-vocabulary.org/#">',
711717
$this->_getParam('wrapper', 'ol'),
712718
$this->_getParam('id', false) ? ' id="' . $this->_getParam('id', '') . '"' : '',
@@ -721,9 +727,12 @@ private function _buildBreadcrumbsHtml()
721727
);
722728
}
723729

724-
foreach ($activeElements as $index => $element) {
725-
$childClasses = array();
730+
foreach ($nodes as $index => $node) {
731+
$nodeTitle = is_array($node) ? (isset($node['title']) ? $node['title'] : Craft::t('Unknown')) : $node->title;
732+
$nodeUrl = is_array($node) ? (isset($node['url']) ? $node['url'] : '') : $node->url;
726733

734+
// Gather node classes
735+
$childClasses = array();
727736
if ($this->_getParam('classDefault', false)) {
728737
$childClasses[] = $this->_getParam('classDefault', '');
729738
}
@@ -733,21 +742,21 @@ private function _buildBreadcrumbsHtml()
733742
$childClasses[] = $this->_getParam('classFirst', 'first');
734743
$breadcrumbs .= sprintf("\n" . '<li%1$s typeof="v:Breadcrumb"><a href="%2$s" title="%3$s" rel="v:url" property="v:title">%3$s</a></li>',
735744
$childClasses ? ' class="' . implode(' ', $childClasses) . '"' : '',
736-
$element->url,
737-
$this->_getParam('renameHome', $element->title)
745+
$nodeUrl,
746+
$this->_getParam('renameHome', $nodeTitle)
738747
);
739748
}
740749
// Last
741750
elseif ($index == $length - 1)
742751
{
743752
$childClasses[] = $this->_getParam('classLast', 'last');
744753
$breadcrumb = sprintf('<span property="v:title">%1$s</span>',
745-
$element->title
754+
$nodeTitle
746755
);
747756
if ($this->_getParam('lastIsLink', false)) {
748757
$breadcrumb = sprintf('<a href="%1$s" title="%2$s" rel="v:url" property="v:title">%2$s</a>',
749-
$element->url,
750-
$element->title
758+
$nodeUrl,
759+
$nodeTitle
751760
);
752761
}
753762
$breadcrumbs .= sprintf("\n" . '<li%1$s typeof="v:Breadcrumb">%2$s</li>',
@@ -758,8 +767,8 @@ private function _buildBreadcrumbsHtml()
758767
else {
759768
$breadcrumbs .= sprintf("\n" . '<li%1$s typeof="v:Breadcrumb"><a href="%2$s" title="%3$s" rel="v:url" property="v:title">%3$s</a></li>',
760769
$childClasses ? ' class="' . implode(' ', $childClasses) . '"' : '',
761-
$element->url,
762-
$element->title
770+
$nodeUrl,
771+
$nodeTitle
763772
);
764773
}
765774
}

translations/nl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'The URL of this node.' => 'De URL van deze node.',
5858
'There are no navigations yet.' => 'Er zijn nog geen navigaties.',
5959
'There are no nodes yet.' => 'Er zijn nog geen nodes.',
60+
'Unknown' => 'Onbekend',
6061
'Whether non-admins can add, edit and delete navigations.' => 'Of gebruikers die geen systeembeheerders zijn, navigaties kunnen toevoegen, wijzigen en verwijderen.',
6162
'Whether non-admins can delete nodes from a specific level. Leave blank if you don’t care.' => 'Of gebruikers die geen systeembeheerders zijn, de nodes vanaf een specifiek niveau kunnen verwijderen. Laat leeg als dit niet uitmaakt.',
6263
'Whether non-admins can move nodes from a specific level. Leave blank if you don’t care.' => 'Of gebruikers die geen systeembeheerders zijn, de nodes vanaf een specifiek niveau kunnen verplaatsen. Laat leeg als dit niet uitmaakt.',

variables/AmNavVariable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ public function getNodeById($id)
122122
* - id ID for the breadcrumbs wrapper.
123123
* - class Class name for the breadcrumbs wrapper.
124124
* - classDefault Default class name for every breadcrumb.
125-
* - classFirst Class name for the first breadcrumb.
125+
* - classFirst Class name for the first breadcrumb.
126126
* - classLast Class name for the last breadcrumb.
127127
* - wrapper Wrapper element without the < and >.
128128
* - beforeText Text before the first item, like 'You are here:'.
129129
* - renameHome Change the title of the home entry.
130130
* - lastIsLink Whether the last breadcrumb should be a link.
131+
* - customNodes Add custom nodes after the elements are handled.
132+
* [ { title: 'A title', url: 'an url' }, { title: 'A title', url: 'an url' } ]
131133
*
132134
* @return string
133135
*/

0 commit comments

Comments
 (0)