Skip to content

Commit 5eb64a1

Browse files
authored
Merge pull request #1597 from hydephp/refactor-main-menu-generation-to-be-deterministic
[2.x] Always place navigation menu items in dropdowns when set in front matter
2 parents e2b14c9 + 353603b commit 5eb64a1

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ protected function canAddRoute(Route $route): bool
120120

121121
protected function canGroupRoute(Route $route): bool
122122
{
123-
if (! $this->usesGroups) {
124-
return false;
125-
}
126-
127123
if (! $this->generatesSidebar) {
128124
return $route->getPage()->navigationMenuGroup() !== null;
129125
}
130126

127+
if (! $this->usesGroups) {
128+
return false;
129+
}
130+
131131
return true;
132132
}
133133

packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,21 @@ public function testMainNavigationMenuWithFrontMatterVisible()
200200
]);
201201
}
202202

203-
public function testMainNavigationMenuWithFrontMatterGroup()
203+
public function testMainNavigationMenuWithExplicitFrontMatterGroupUsesDropdownsRegardlessOfConfigSetting()
204204
{
205-
// TODO: For new v2 system, this should insert a root item with the group name and the children as the pages
206-
207205
$this->assertMenuEquals([
208-
['label' => 'Foo', 'group' => 'group-1'],
209-
['label' => 'Bar', 'group' => 'group-1'],
210-
['label' => 'Baz', 'group' => 'group-1'],
206+
['label' => 'Group 1', 'children' => ['Foo', 'Bar', 'Baz']],
211207
], [
212208
new MarkdownPage('foo', ['navigation.group' => 'Group 1']),
213209
new MarkdownPage('bar', ['navigation.group' => 'Group 1']),
214210
new MarkdownPage('baz', ['navigation.group' => 'Group 1']),
215211
]);
216212
}
217213

218-
public function testMainNavigationMenuWithFrontMatterCategory()
214+
public function testMainNavigationMenuWithExplicitFrontMatterCategoryUsesDropdownsRegardlessOfConfigSetting()
219215
{
220-
// TODO: For new v2 system, this should insert a root item with the group name and the children as the pages
221-
222216
$this->assertMenuEquals([
223-
['label' => 'Foo', 'group' => 'group-1'],
224-
['label' => 'Bar', 'group' => 'group-1'],
225-
['label' => 'Baz', 'group' => 'group-1'],
217+
['label' => 'Group 1', 'children' => ['Foo', 'Bar', 'Baz']],
226218
], [
227219
new MarkdownPage('foo', ['navigation.category' => 'Group 1']),
228220
new MarkdownPage('bar', ['navigation.category' => 'Group 1']),
@@ -292,7 +284,10 @@ public function testMainNavigationMenuWithFrontMatterGroupAndCategory()
292284
{
293285
// Since the main key in the navigation schema is 'group', that takes precedence over its 'category' alias
294286

295-
$this->assertMenuEquals(array_fill(0, 3, ['group' => 'group-1']), [
287+
$this->assertMenuEquals([[
288+
'label' => 'Group 1',
289+
'children' => ['Foo', 'Bar', 'Baz'],
290+
]], [
296291
new MarkdownPage('foo', ['navigation.group' => 'Group 1', 'navigation.category' => 'Group 2']),
297292
new MarkdownPage('bar', ['navigation.group' => 'Group 1', 'navigation.category' => 'Group 2']),
298293
new MarkdownPage('baz', ['navigation.group' => 'Group 1', 'navigation.category' => 'Group 2']),
@@ -494,8 +489,8 @@ public function testMainNavigationMenuItemsWithTheSameLabelAreNotFilteredForDupl
494489
public function testMainNavigationMenuItemsWithSameLabelButDifferentGroupsAreNotFiltered()
495490
{
496491
$this->assertMenuEquals([
497-
['label' => 'Foo', 'group' => 'group-1'],
498-
['label' => 'Foo', 'group' => 'group-2'],
492+
['label' => 'Group 1', 'children' => ['Foo']],
493+
['label' => 'Group 2', 'children' => ['Foo']],
499494
], [
500495
new MarkdownPage('foo', ['navigation.label' => 'Foo', 'navigation.group' => 'Group 1']),
501496
new MarkdownPage('bar', ['navigation.label' => 'Foo', 'navigation.group' => 'Group 2']),

0 commit comments

Comments
 (0)