Skip to content

Commit 6a076b8

Browse files
committed
Let the generator parse navigation items instead of the loader
We "lose" out on the null defaults, but they don't offer any value anyways.
1 parent 138e4b9 commit 6a076b8

File tree

2 files changed

+3
-31
lines changed

2 files changed

+3
-31
lines changed

packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Throwable;
88
use Illuminate\Support\Arr;
9-
use Hyde\Facades\Navigation;
109
use Hyde\Foundation\Application;
1110
use Illuminate\Config\Repository;
1211
use Hyde\Framework\Features\Blogging\Models\PostAuthor;
@@ -52,10 +51,6 @@ protected function mergeParsedConfiguration(): void
5251
$data['authors'] = $this->parseAuthors($data['authors']);
5352
}
5453

55-
if ($namespace === 'hyde' && isset($data['navigation']['custom'])) {
56-
$data['navigation']['custom'] = $this->parseNavigationItems($data['navigation']['custom']);
57-
}
58-
5954
$this->mergeConfiguration($namespace, Arr::undot($data ?: []));
6055
}
6156
}
@@ -82,24 +77,4 @@ protected function parseAuthors(array $authors): array
8277
}
8378
});
8479
}
85-
86-
/**
87-
* @experimental Since the main configuration also uses arrays, the only thing this method really does is to rethrow any exceptions.
88-
*
89-
* @param array<array{destination: string, label: ?string, priority: ?int, attributes: array<string, scalar>}> $items Where destination is a route key or an external URI.
90-
* @return array<array{destination: string, label: ?string, priority: ?int, attributes: array<string, scalar>}>
91-
*/
92-
protected function parseNavigationItems(array $items): array
93-
{
94-
return Arr::map($items, function (array $item): array {
95-
try {
96-
return Navigation::item(...$item);
97-
} catch (Throwable $exception) {
98-
throw new InvalidConfigurationException(
99-
'Invalid navigation item configuration detected the configuration file. Please double check the syntax.',
100-
previous: $exception
101-
);
102-
}
103-
});
104-
}
10580
}

packages/framework/tests/Feature/YamlConfigurationFeatureTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,14 @@ public function testCanSetCustomNavigationItemsInTheYamlConfig()
501501
'destination' => 'https://example.com',
502502
'label' => 'Example',
503503
'priority' => 100,
504-
'attributes' => [],
505504
], [
506505
'destination' => 'about',
507506
'label' => 'About Us',
508507
'priority' => 200,
509-
'attributes' => [],
510508
], [
511509
'destination' => 'contact',
512510
'label' => 'Contact',
513511
'priority' => 300,
514-
'attributes' => [],
515512
],
516513
], $configItems);
517514

@@ -615,9 +612,6 @@ public function testOnlyNeedToAddDestinationToYamlConfiguredNavigationItems()
615612
$this->assertSame([
616613
[
617614
'destination' => 'about.html',
618-
'label' => null,
619-
'priority' => null,
620-
'attributes' => [],
621615
],
622616
], $configItems);
623617

@@ -675,6 +669,7 @@ public function testTypeErrorsInNavigationYamlConfigAreRethrownMoreHelpfully()
675669

676670
try {
677671
$this->runBootstrappers();
672+
NavigationMenuGenerator::handle(MainNavigationMenu::class)->getItems()->all();
678673
} catch (InvalidConfigurationException $exception) {
679674
$exceptionThrown = true;
680675
$this->assertSame('Invalid navigation item configuration detected the configuration file. Please double check the syntax.', $exception->getMessage());
@@ -697,6 +692,7 @@ public function testMustAddDestinationToYamlConfiguredNavigationItems()
697692

698693
try {
699694
$this->runBootstrappers();
695+
NavigationMenuGenerator::handle(MainNavigationMenu::class)->getItems()->all();
700696
} catch (InvalidConfigurationException $exception) {
701697
$exceptionThrown = true;
702698
$this->assertSame('Invalid navigation item configuration detected the configuration file. Please double check the syntax.', $exception->getMessage());
@@ -720,6 +716,7 @@ public function testAddingExtraYamlNavigationItemFieldsThrowsAnException()
720716

721717
try {
722718
$this->runBootstrappers();
719+
NavigationMenuGenerator::handle(MainNavigationMenu::class)->getItems()->all();
723720
} catch (InvalidConfigurationException $exception) {
724721
$exceptionThrown = true;
725722
$this->assertSame('Invalid navigation item configuration detected the configuration file. Please double check the syntax.', $exception->getMessage());

0 commit comments

Comments
 (0)