Skip to content

Commit 4e9abe2

Browse files
committed
Merge branch 'v5' into v5.0.11
2 parents 9c6f35b + 2b459bb commit 4e9abe2

File tree

7 files changed

+98
-50
lines changed

7 files changed

+98
-50
lines changed

CHANGELOG/CHANGELOG-CORE.md

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

3+
## 5.0.10 - 2026-02-16
4+
5+
### Changed
6+
7+
- Updated `BarrelStrength\Sprout\core\modules\CpNavHelper` to improve support for nav item positioning
8+
9+
## 5.0.8 - 2026-02-14
10+
11+
### Fixed
12+
13+
- Fixed module nav items positioning in Craft 5.9 ([#372])
14+
15+
[#372]: https://github.com/barrelstrength/sprout/issues/372
16+
317
## 5.0.3 - 2025-03-07
418

519
### Fixed

CHANGELOG/CHANGELOG-DATA-STUDIO.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.9 - 2025-02-16
4+
5+
### Fixed
6+
7+
- Fixed settings field layout type assignment ([#373])
8+
9+
[#373]: https://github.com/barrelstrength/sprout/issues/373
10+
311
## 5.0.4 - 2025-03-09
412

513
### Fixed

CHANGELOG/CHANGELOG-REDIRECTS.md

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

3+
## 5.0.9 - 2025-02-16
4+
5+
- Fixed settings field layout type assignment ([#362])
6+
7+
[#362]: https://github.com/barrelstrength/sprout/issues/362
8+
39
## 5.0.6 - 2025-03-21
410

511
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "barrelstrength/sprout",
33
"description": "The Sprout Framework module",
44
"type": "craft-module",
5-
"version": "5.0.6",
5+
"version": "5.0.10",
66
"license": "proprietary",
77
"authors": [
88
{

src/core/modules/CpNavHelper.php

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,43 @@
22

33
namespace BarrelStrength\Sprout\core\modules;
44

5+
use BarrelStrength\Sprout\core\db\SproutPluginMigrationInterface;
56
use BarrelStrength\Sprout\core\Sprout;
7+
use Craft;
8+
use Illuminate\Support\Collection;
69

710
class CpNavHelper
811
{
912
/**
1013
* Updates Craft's CP sidebar navigation to include nav items for Sprout modules
14+
*
15+
* Add $hasCpSection to any Sprout plugin that uses modules that should be added to the CP sidebar navigation.
1116
*/
1217
public static function getUpdatedCpNavItems(array $cpNavItems): array
1318
{
14-
$beforePluginNavItemKeys = [
15-
'dashboard',
16-
'entries',
17-
'globals',
18-
'categories',
19-
'assets',
20-
'users',
21-
];
22-
23-
$afterPluginNavItemKeys = [
24-
'graphql',
25-
'utilities',
26-
'settings',
27-
'plugin-store',
28-
];
29-
30-
$newCpNavItems = [];
31-
$afterCpNavItems = [];
32-
$otherCpNavItems = [];
33-
34-
// Break out the current nav into multiple arrays that we can re-assemble later
35-
// 1. Craft defaults at the top of the nav
36-
// 2. Plugins and stuff
37-
// 3. Craft defaults and settings at bottom of nav
38-
foreach ($cpNavItems as $cpNavItem) {
39-
switch (true) {
40-
case in_array($cpNavItem['url'], $beforePluginNavItemKeys, true):
41-
$newCpNavItems[] = $cpNavItem;
42-
break;
43-
44-
case in_array($cpNavItem['url'], $afterPluginNavItemKeys, true):
45-
$afterCpNavItems[] = $cpNavItem;
46-
break;
47-
default:
48-
$otherCpNavItems[] = $cpNavItem;
49-
break;
19+
$plugins = Craft::$app->getPlugins()->getAllPlugins();
20+
21+
$pluginsWithCpSections = array_filter($plugins, static function($plugin) {
22+
return $plugin->hasCpSection;
23+
});
24+
25+
// We have to enable $hasCpSection in each plugin then remove the default output just in case no other plugins with CP sections are installed
26+
$cpNavSproutPluginNavKeys = array_keys(array_filter($pluginsWithCpSections, static function($plugin) {
27+
return $plugin instanceof SproutPluginMigrationInterface;
28+
}));
29+
30+
// get the nav items of the plugins with cp sections from the $cpNavItems based on the $pluginsWithCpSections matching the url to the plugin handle
31+
$cpNavOldPluginNavItems = array_filter($cpNavItems, static function($navItem) use ($pluginsWithCpSections) {
32+
foreach ($pluginsWithCpSections as $plugin) {
33+
if ($navItem['url'] === $plugin->handle) {
34+
return true;
35+
}
5036
}
51-
}
37+
38+
return false;
39+
});
40+
41+
$cpNavSproutModuleNavItems = [];
5242

5343
$sproutNavGroupsInfo = Sprout::getInstance()->coreSettings->getCraftCpSidebarNavItems();
5444
$sproutNavGroups = [];
@@ -100,31 +90,55 @@ public static function getUpdatedCpNavItems(array $cpNavItems): array
10090
unset($sproutNavGroup['subnav']);
10191
}
10292

103-
$otherCpNavItems[] = $sproutNavGroup;
93+
$cpNavSproutModuleNavItems[] = $sproutNavGroup;
10494
}
10595

106-
// Sort custom nav items alphabetically by label
107-
uasort($otherCpNavItems, static fn($a, $b) => $a['label'] <=> $b['label']);
96+
$cpNavNewPluginNavItems = array_merge($cpNavOldPluginNavItems, $cpNavSproutModuleNavItems);
10897

109-
// Add the custom nav items back to the nav
110-
foreach ($otherCpNavItems as $otherCpNavItem) {
111-
$newCpNavItems[] = $otherCpNavItem;
112-
}
98+
$cpNavNewPluginNavItems = array_filter($cpNavNewPluginNavItems, static function($navItem) use ($cpNavSproutPluginNavKeys) {
99+
foreach ($cpNavSproutPluginNavKeys as $sproutNavKey) {
100+
if ($navItem['url'] === $sproutNavKey) {
101+
return false;
102+
}
103+
}
104+
105+
return true;
106+
});
113107

114-
// Add the Craft defaults back to the bottom of the nav
115-
foreach ($afterCpNavItems as $afterCpNavItem) {
116-
$newCpNavItems[] = $afterCpNavItem;
108+
uasort($cpNavNewPluginNavItems, static fn($a, $b) => $a['label'] <=> $b['label']);
109+
110+
// Remove all the Sprout Plugin hasCpSection nav items
111+
$newCpNavItems = array_filter($cpNavItems, static function($navItem) use ($pluginsWithCpSections) {
112+
foreach ($pluginsWithCpSections as $plugin) {
113+
if ($navItem['url'] === $plugin->handle) {
114+
return false;
115+
}
116+
}
117+
118+
return true;
119+
});
120+
121+
// 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);
124+
125+
// 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
126+
if ($cpNavFirstPluginItemIndex === false) {
127+
$cpNavFirstPluginItemIndex = count($newCpNavItems);
117128
}
118129

130+
// Insert the Sprout Module nav items
131+
array_splice($newCpNavItems, $cpNavFirstPluginItemIndex, 0, $cpNavNewPluginNavItems);
132+
119133
return $newCpNavItems;
120134
}
121135

122136
/**
123137
* Adds nav items for a give module to the Sprout settings sidebar navigation
124138
*/
125139
public static function mergeSproutCpSettingsNavItems(
126-
array $oldNavItems,
127-
array $newNavItems,
140+
array $oldNavItems,
141+
array $newNavItems,
128142
string $groupName,
129143
): array {
130144
$navItems = $oldNavItems;

src/datastudio/DataStudioSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function getFieldLayout(): FieldLayout
3535
{
3636
// If there is a field layout, it's saved with a UID key and we just need the first value
3737
if ($fieldLayout = reset($this->fieldLayouts)) {
38+
// @todo - this `type` value should be saved to the project config with the correct type but appears to be missing per one ticket. fix this in upgrade migrations
39+
$fieldLayout['type'] = DataSetElement::class;
40+
3841
return FieldLayout::createFromConfig($fieldLayout);
3942
}
4043

src/redirects/RedirectsSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ public function getFieldLayout(): FieldLayout
153153
{
154154
// If there is a field layout, it's saved with a UID key and we just need the first value
155155
if ($fieldLayout = reset($this->fieldLayouts)) {
156+
// @todo - this `type` value should be saved to the project config with the correct type but appears to be missing per one ticket. fix this in upgrade migrations
157+
$fieldLayout['type'] = RedirectElement::class;
158+
156159
return FieldLayout::createFromConfig($fieldLayout);
157160
}
158161

0 commit comments

Comments
 (0)