From 4622ee3cf794f56c0f7a228b63ff6b1f05ff4d39 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 7 Nov 2023 10:24:14 +0100 Subject: [PATCH] Support both route keys and identifiers for specifying sidebar order - Supports route keys for consistency with the navigation config. - Supports identifiers for backwards compatibility and ease of use, as the route key prefix is redundant due to it being the same for all documentation pages. --- .../Factories/NavigationDataFactory.php | 3 ++- .../Unit/NavigationDataFactoryUnitTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index 95492b0e4f2..be6655de73e 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -162,7 +162,8 @@ private function searchForPriorityInSidebarConfig(): ?int /** @var array|array $config */ $config = Config::getArray('docs.sidebar_order', []); - return $this->parseNavigationPriorityConfig($config, 'identifier'); + return $this->parseNavigationPriorityConfig($config, 'routeKey') // For consistency with the navigation config. + ?? $this->parseNavigationPriorityConfig($config, 'identifier'); // For backwards compatibility and ease of use } private function searchForPriorityInNavigationConfig(): ?int diff --git a/packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php b/packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php index 539d080fc04..a118c695723 100644 --- a/packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php +++ b/packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php @@ -128,6 +128,24 @@ public function testSearchForPriorityInNavigationConfigForDocumentationPageSuppo $this->assertSame(999, $factory->makePriority()); } + public function testRouteKeysCanBeUsedForDocumentationSidebarPriorities() + { + self::mockConfig(['docs.sidebar_order' => [ + 'key/foo', + 'key/bar', + 'baz', + ]]); + + $factory = new NavigationConfigTestClass($this->makeCoreDataObject('foo', routeKey: 'key/foo', pageClass: DocumentationPage::class)); + $this->assertSame(500, $factory->makePriority()); + + $factory = new NavigationConfigTestClass($this->makeCoreDataObject('bar', routeKey: 'key/bar', pageClass: DocumentationPage::class)); + $this->assertSame(501, $factory->makePriority()); + + $factory = new NavigationConfigTestClass($this->makeCoreDataObject('baz', routeKey: 'key', pageClass: DocumentationPage::class)); + $this->assertSame(502, $factory->makePriority()); + } + protected function makeCoreDataObject(string $identifier = '', string $routeKey = '', string $pageClass = MarkdownPage::class): CoreDataObject { return new CoreDataObject(new FrontMatter(), new Markdown(), $pageClass, $identifier, '', '', $routeKey);