Skip to content

Commit

Permalink
Merge pull request #216 from hydephp/215-add-a-navitemtoroute-helper
Browse files Browse the repository at this point in the history
Add a NavItem::toRoute() helper
  • Loading branch information
caendesilva authored Jul 10, 2022
2 parents 4d48444 + f536688 commit ec64445
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/framework/src/Models/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static function toLink(string $href, string $title, int $priority = 500):
return (new self(null, $title, $priority, false))->setDestination($href);
}

/**
* Create a new navigation menu item leading to a Route model.
*/
public static function toRoute(RouteContract $route, string $title, int $priority = 500): static
{
return new self($route, $title, $priority, false);
}

/**
* Resolve a link to the navigation item.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/framework/tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public function testToLink()
$this->assertFalse($item->hidden);
}

public function testToRoute()
{
$route = Route::get('index');
$item = NavItem::toRoute($route, 'foo', 10);

$this->assertSame($route, $item->route);
$this->assertSame('foo', $item->title);
$this->assertSame(10, $item->priority);
$this->assertFalse($item->hidden);
}

public function testIsCurrentRoute()
{
$route = Route::get('index');
Expand Down

0 comments on commit ec64445

Please sign in to comment.