Skip to content

Commit 5e27628

Browse files
committed
Add configuration helper to the Navigation facade to create item array
1 parent 17cd699 commit 5e27628

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/framework/src/Facades/Navigation.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44

55
namespace Hyde\Facades;
66

7+
use function compact;
8+
79
/**
810
* General facade for navigation features.
911
*/
1012
class Navigation
1113
{
12-
//
14+
/**
15+
* Configuration helper method to define a new navigation item, with better IDE support.
16+
*
17+
* The returned array will then be used by the framework to create a new NavigationItem instance.
18+
*
19+
* @see https://hydephp.com/docs/2.x/navigation-api
20+
*
21+
* @param string<\Hyde\Support\Models\RouteKey>|string $destination Route key, or an external URI.
22+
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
23+
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
24+
*/
25+
public static function item(string $destination, ?string $label = null, ?int $priority = null): array
26+
{
27+
return compact('destination', 'label', 'priority');
28+
}
1329
}

packages/framework/tests/Unit/Facades/NavigationFacadeTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@
44

55
namespace Hyde\Framework\Testing\Unit\Facades;
66

7+
use Hyde\Facades\Navigation;
78
use Hyde\Testing\UnitTestCase;
89

910
/**
1011
* @covers \Hyde\Facades\Navigation
1112
*/
1213
class NavigationFacadeTest extends UnitTestCase
1314
{
14-
//
15+
public function testItem(): void
16+
{
17+
$item = Navigation::item('home', 'Home', 100);
18+
19+
$this->assertSame([
20+
'destination' => 'home',
21+
'label' => 'Home',
22+
'priority' => 100,
23+
], $item);
24+
}
25+
26+
public function testItemWithOnlyDestination(): void
27+
{
28+
$item = Navigation::item('home');
29+
30+
$this->assertSame([
31+
'destination' => 'home',
32+
'label' => null,
33+
'priority' => null,
34+
], $item);
35+
}
1536
}

0 commit comments

Comments
 (0)