Skip to content

Commit 3bcafeb

Browse files
committed
Extract helper method
1 parent 4a36e29 commit 3bcafeb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ public function __construct(Route|string $destination, string $label, int $prior
3737
*/
3838
public static function create(Route|string $destination, ?string $label = null, ?int $priority = null): static
3939
{
40-
if (is_string($destination) && Routes::has($destination)) {
41-
$destination = Routes::get($destination);
42-
}
43-
44-
if ($destination instanceof Route) {
45-
$label ??= $destination->getPage()->navigationMenuLabel();
46-
$priority ??= $destination->getPage()->navigationMenuPriority();
47-
}
48-
49-
return new static($destination, $label ?? $destination, $priority ?? NavigationMenu::DEFAULT);
40+
return new static(...self::make($destination, $label, $priority));
5041
}
5142

5243
/**
@@ -96,4 +87,18 @@ public function isActive(): bool
9687
{
9788
return Hyde::currentRoute()?->getLink() === $this->getLink();
9889
}
90+
91+
protected static function make(Route|string $destination, ?string $label = null, ?int $priority = null): array
92+
{
93+
if (is_string($destination) && Routes::has($destination)) {
94+
$destination = Routes::get($destination);
95+
}
96+
97+
if ($destination instanceof Route) {
98+
$label ??= $destination->getPage()->navigationMenuLabel();
99+
$priority ??= $destination->getPage()->navigationMenuPriority();
100+
}
101+
102+
return [$destination, $label ?? $destination, $priority ?? NavigationMenu::DEFAULT];
103+
}
99104
}

0 commit comments

Comments
 (0)