diff --git a/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php b/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php index d2bd01921f8..c9a0ad405d6 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php +++ b/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php @@ -81,9 +81,9 @@ protected function generate(): void $this->items->push(NavigationItem::create(DocumentationPage::home())); } } else { - collect(Config::getArray('hyde.navigation.custom', []))->each(function (NavigationItem $item): void { + collect(Config::getArray('hyde.navigation.custom', []))->each(function (array $item): void { // Since these were added explicitly by the user, we can assume they should always be shown - $this->items->push($item); + $this->items->push(NavigationItem::create($item['destination'], $item['label'] ?? null, $item['priority'] ?? null)); }); } } diff --git a/packages/framework/tests/Feature/NavigationMenuTest.php b/packages/framework/tests/Feature/NavigationMenuTest.php index 7f6cb8b3ac7..3c6876935c3 100644 --- a/packages/framework/tests/Feature/NavigationMenuTest.php +++ b/packages/framework/tests/Feature/NavigationMenuTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Hyde; +use Hyde\Facades\Navigation; use Hyde\Support\Models\Route; use Hyde\Foundation\Facades\Routes; use Hyde\Framework\Features\Navigation\NavigationGroup; @@ -91,9 +92,39 @@ public function testIsSortedAutomaticallyWhenUsingNavigationMenuCreate() $this->assertEquals($expected, $menu->getItems()); } + public function testCanAddCustomLinksInConfig() + { + config(['hyde.navigation.custom' => [Navigation::item('foo', 'Foo')]]); + + $menu = $this->createNavigationMenu(); + + $expected = collect([ + NavigationItem::create(Routes::get('index')), + NavigationItem::create('foo', 'Foo'), + ]); + + $this->assertCount(count($expected), $menu->getItems()); + $this->assertEquals($expected, $menu->getItems()); + } + + public function testCanAddCustomLinksInConfigAsArray() + { + config(['hyde.navigation.custom' => [['destination' => 'foo', 'label' => 'Foo']]]); + + $menu = $this->createNavigationMenu(); + + $expected = collect([ + NavigationItem::create(Routes::get('index')), + NavigationItem::create('foo', 'Foo'), + ]); + + $this->assertCount(count($expected), $menu->getItems()); + $this->assertEquals($expected, $menu->getItems()); + } + public function testExternalLinkCanBeAddedInConfig() { - config(['hyde.navigation.custom' => [NavigationItem::create('https://example.com', 'foo')]]); + config(['hyde.navigation.custom' => [Navigation::item('https://example.com', 'foo')]]); $menu = $this->createNavigationMenu(); @@ -108,7 +139,7 @@ public function testExternalLinkCanBeAddedInConfig() public function testPathLinkCanBeAddedInConfig() { - config(['hyde.navigation.custom' => [NavigationItem::create('foo', 'foo')]]); + config(['hyde.navigation.custom' => [Navigation::item('foo', 'foo')]]); $menu = $this->createNavigationMenu(); @@ -124,8 +155,8 @@ public function testPathLinkCanBeAddedInConfig() public function testDuplicatesAreNotRemovedWhenAddingInConfig() { config(['hyde.navigation.custom' => [ - NavigationItem::create('foo', 'foo'), - NavigationItem::create('foo', 'foo'), + Navigation::item('foo', 'foo'), + Navigation::item('foo', 'foo'), ]]); $menu = $this->createNavigationMenu(); @@ -143,8 +174,8 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfig() public function testDuplicatesAreNotRemovedWhenAddingInConfigRegardlessOfDestination() { config(['hyde.navigation.custom' => [ - NavigationItem::create('foo', 'foo'), - NavigationItem::create('bar', 'foo'), + Navigation::item('foo', 'foo'), + Navigation::item('bar', 'foo'), ]]); $menu = $this->createNavigationMenu(); @@ -163,7 +194,7 @@ public function testConfigItemsTakePrecedenceOverGeneratedItems() { $this->file('_pages/foo.md'); - config(['hyde.navigation.custom' => [NavigationItem::create('bar', 'Foo')]]); + config(['hyde.navigation.custom' => [Navigation::item('bar', 'Foo')]]); $menu = $this->createNavigationMenu();