diff --git a/CHANGELOG.md b/CHANGELOG.md index 570b9449988..043eccebfa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed a bug where element selection modals were only showing the first 100 elements. ([#14790](https://github.com/craftcms/cms/issues/14790)) - Fixed a PHP error that could occur on the Dashboard if any Quick Post widgets hadn’t been saved since before Craft 1.2. ([#14794](https://github.com/craftcms/cms/issues/14794)) - Fixed a bug where double-clicking on an inline Matrix block tab would cause it to expand/collapse. ([#14791](https://github.com/craftcms/cms/issues/14791)) +- Fixed a bug where site breadcrumbs weren’t getting hyperlinked for installs with multiple site groups. ([#14802](https://github.com/craftcms/cms/issues/14802)) ## 5.0.4 - 2024-04-10 diff --git a/src/templates/_layouts/components/crumbs.twig b/src/templates/_layouts/components/crumbs.twig index 13a2d0974d3..27ca8893eb9 100644 --- a/src/templates/_layouts/components/crumbs.twig +++ b/src/templates/_layouts/components/crumbs.twig @@ -6,9 +6,7 @@ {% for crumb in crumbs %} {% set hasMenuItems = crumb.menu is defined and crumb.menu.items is defined %} {% if hasMenuItems %} - {% set crumb = ( - crumb.menu.items|map(o => (o.group ?? false) ? (o.options ?? []) : [o])|flatten(1)|firstWhere(o => o.selected ?? false) ?: {} - )|merge(crumb) %} + {% set crumb = findCrumb(crumb.menu.items)|merge(crumb) %} {% endif %} {% tag 'li' with { diff --git a/src/web/twig/CpExtension.php b/src/web/twig/CpExtension.php index 07b067d910c..4dbc59f9dbb 100644 --- a/src/web/twig/CpExtension.php +++ b/src/web/twig/CpExtension.php @@ -48,9 +48,31 @@ public function getFunctions(): array new TwigFunction('elementCard', [Cp::class, 'elementCardHtml'], ['is_safe' => ['html']]), new TwigFunction('elementChip', [Cp::class, 'elementChipHtml'], ['is_safe' => ['html']]), new TwigFunction('elementIndex', [Cp::class, 'elementIndexHtml'], ['is_safe' => ['html']]), + new TwigFunction('findCrumb', fn(array $items) => $this->findCrumb($items)), new TwigFunction('iconSvg', [Cp::class, 'iconSvg'], ['is_safe' => ['html']]), new TwigFunction('siteMenuItems', [Cp::class, 'siteMenuItems']), new TwigFunction('statusIndicator', [Cp::class, 'statusIndicatorHtml'], ['is_safe' => ['html']]), ]; } + + private function findCrumb(array $items): array + { + foreach ($items as $item) { + if (array_key_exists('selected', $item)) { + if ($item['selected']) { + return $item; + } + continue; + } + + if (isset($item['items'])) { + $selected = $this->findCrumb($item['items']); + if (!empty($selected)) { + return $selected; + } + } + } + + return []; + } }