Skip to content

Commit

Permalink
Extract helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 26, 2024
1 parent 4a36e29 commit 3bcafeb
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ public function __construct(Route|string $destination, string $label, int $prior
*/
public static function create(Route|string $destination, ?string $label = null, ?int $priority = null): static
{
if (is_string($destination) && Routes::has($destination)) {
$destination = Routes::get($destination);
}

if ($destination instanceof Route) {
$label ??= $destination->getPage()->navigationMenuLabel();
$priority ??= $destination->getPage()->navigationMenuPriority();
}

return new static($destination, $label ?? $destination, $priority ?? NavigationMenu::DEFAULT);
return new static(...self::make($destination, $label, $priority));
}

/**
Expand Down Expand Up @@ -96,4 +87,18 @@ public function isActive(): bool
{
return Hyde::currentRoute()?->getLink() === $this->getLink();
}

protected static function make(Route|string $destination, ?string $label = null, ?int $priority = null): array
{
if (is_string($destination) && Routes::has($destination)) {
$destination = Routes::get($destination);
}

if ($destination instanceof Route) {
$label ??= $destination->getPage()->navigationMenuLabel();
$priority ??= $destination->getPage()->navigationMenuPriority();
}

return [$destination, $label ?? $destination, $priority ?? NavigationMenu::DEFAULT];
}
}

0 comments on commit 3bcafeb

Please sign in to comment.