Skip to content

Commit 11b9e46

Browse files
committed
Updates nav logic to lean on getCpNavItem data instead of handle
1 parent dc87f09 commit 11b9e46

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG/CHANGELOG-CORE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 5.0.12 - UNRELEASED
4+
5+
### Fixed
6+
7+
- Fixed module nav items positioning when nav items use different value than plugin handles ([#372])
8+
9+
[#372]: https://github.com/barrelstrength/sprout/issues/372
10+
311
## 5.0.10 - 2026-02-16
412

513
### Changed

src/core/modules/CpNavHelper.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public static function getUpdatedCpNavItems(array $cpNavItems): array
3030
// get the nav items of the plugins with cp sections from the $cpNavItems based on the $pluginsWithCpSections matching the url to the plugin handle
3131
$cpNavOldPluginNavItems = array_filter($cpNavItems, static function($navItem) use ($pluginsWithCpSections) {
3232
foreach ($pluginsWithCpSections as $plugin) {
33-
if ($navItem['url'] === $plugin->handle) {
33+
$cpNavItem = $plugin->getCpNavItem();
34+
$pluginNavItemUrl = $cpNavItem['url'] ?? null;
35+
if ($navItem['url'] === $pluginNavItemUrl) {
3436
return true;
3537
}
3638
}
@@ -110,7 +112,9 @@ public static function getUpdatedCpNavItems(array $cpNavItems): array
110112
// Remove all the Sprout Plugin hasCpSection nav items
111113
$newCpNavItems = array_filter($cpNavItems, static function($navItem) use ($pluginsWithCpSections) {
112114
foreach ($pluginsWithCpSections as $plugin) {
113-
if ($navItem['url'] === $plugin->handle) {
115+
$cpNavItem = $plugin->getCpNavItem();
116+
$pluginNavItemUrl = $cpNavItem['url'] ?? null;
117+
if ($navItem['url'] === $pluginNavItemUrl) {
114118
return false;
115119
}
116120
}
@@ -119,8 +123,10 @@ public static function getUpdatedCpNavItems(array $cpNavItems): array
119123
});
120124

121125
// If no other plugins are installed and no modules are enabled, this will be the Sprout plugin and just get removed later
122-
$cpNavFirstPluginItemKey = array_key_first($pluginsWithCpSections);
123-
$cpNavFirstPluginItemIndex = Collection::make($cpNavItems)->search(fn(array $item) => $item['url'] === $cpNavFirstPluginItemKey);
126+
$firstPlugin = reset($pluginsWithCpSections);
127+
$firstCpNavItem = $firstPlugin->getCpNavItem();
128+
$firstPluginNavItemUrl = $firstCpNavItem['url'] ?? null;
129+
$cpNavFirstPluginItemIndex = Collection::make($cpNavItems)->search(fn(array $item) => $item['url'] === $firstPluginNavItemUrl);
124130

125131
// If we don't find any plugins with CP sections (a Sprout Plugin should always be there), we'll just add the Sprout Modules to the end of the nav
126132
if ($cpNavFirstPluginItemIndex === false) {

0 commit comments

Comments
 (0)