Skip to content

Commit

Permalink
Fixed #14802
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 13, 2024
1 parent feeda10 commit c92528d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/templates/_layouts/components/crumbs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions src/web/twig/CpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}

0 comments on commit c92528d

Please sign in to comment.