diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 01955fff841..1c7e3aa81e5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -12,15 +12,15 @@ This serves two purposes: ### Added - Added a new `\Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets` build task handle media assets transfers for site builds. - Added a new `ExternalRoute` class to represent external routes. -- Added a new `NavItem::getLink()` method contain the previous `NavItem::getDestination()` logic, to return the link URL. +- Added a new `NavigationItem::getLink()` method contain the previous `NavigationItem::getDestination()` logic, to return the link URL. ### Changed - Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task. - Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method. - Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566 - Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573 -- Breaking: The `NavItem` class now always stores the destination as a `Route` instance. -- Breaking: The `NavItem::getDestination()` method now returns its `Route` instance. +- Breaking: The `NavigationItem` class now always stores the destination as a `Route` instance. +- Breaking: The `NavigationItem::getDestination()` method now returns its `Route` instance. ### Deprecated - for soon-to-be removed features. @@ -63,11 +63,11 @@ For more information, see https://github.com/hydephp/develop/pull/1498. ### Navigation item changes -The `NavItem::getDestination()` method now returns its `Route` instance. This allows for deferring the route evaluation. +The `NavigationItem::getDestination()` method now returns its `Route` instance. This allows for deferring the route evaluation. If you have previously used this method directly and expected a string to be returned, you may need to adapt your code to handle the new return type. -If you want to retain the previous state where a string is always returned, you can use the new `NavItem::getLink()` method instead, which will resolve the route immediately. +If you want to retain the previous state where a string is always returned, you can use the new `NavigationItem::getLink()` method instead, which will resolve the route immediately. ### HTML ID changes diff --git a/config/hyde.php b/config/hyde.php index 9cbbe1cceb3..65fa6d4394f 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -350,7 +350,7 @@ // To get started quickly, you can uncomment the defaults here. // See the documentation link above for more information. 'custom' => [ - // NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200), + // NavigationItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200), ], // How should pages in subdirectories be displayed in the menu? diff --git a/docs/digging-deeper/navigation.md b/docs/digging-deeper/navigation.md index 794fda31d35..761506488f2 100644 --- a/docs/digging-deeper/navigation.md +++ b/docs/digging-deeper/navigation.md @@ -230,9 +230,9 @@ To remove items from being automatically added, simply add the page's route key ### Adding Custom Navigation Menu Links -You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavItem` model to the `navigation.custom` array. +You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavigationItem` model to the `navigation.custom` array. -When linking to an external site, you should use the `NavItem::forLink()` method facade. The first two arguments are the +When linking to an external site, you should use the `NavigationItem::forLink()` method facade. The first two arguments are the destination and label, both required. The third argument is the priority, which is optional, and defaults to `500`. ```php @@ -314,14 +314,14 @@ use Hyde\Framework\Features\Navigation\BaseNavigationMenu; Within the `BaseNavigationMenu` class, you will find the main logic for how the menus are generated, while the child implementations contain the extra logic tailored for their specific use cases. -All the navigation menus store the menu items in their `$items` array containing instances of the `NavItem` class. +All the navigation menus store the menu items in their `$items` array containing instances of the `NavigationItem` class. -The `NavItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu. -Dropdowns are represented by `DropdownNavItem` instances, which extend the `NavItem` class and contain an array of additional `NavItem` instances. +The `NavigationItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu. +Dropdowns are represented by `DropdownNavigationItem` instances, which extend the `NavigationItem` class and contain an array of additional `NavigationItem` instances. ```php use Hyde\Framework\Features\Navigation\NavigationItem; -use Hyde\Framework\Features\Navigation\DropdownNavItem; +use Hyde\Framework\Features\Navigation\DropdownNavigationItem; ``` ## The Navigation API diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 9cbbe1cceb3..65fa6d4394f 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -350,7 +350,7 @@ // To get started quickly, you can uncomment the defaults here. // See the documentation link above for more information. 'custom' => [ - // NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200), + // NavigationItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200), ], // How should pages in subdirectories be displayed in the menu? diff --git a/packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php b/packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php index d234ed0fcdc..8a9edb0e19b 100644 --- a/packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php +++ b/packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php @@ -66,7 +66,7 @@ public function hasGroups(): bool * * For index pages, this will also return true for the first group in the menu, unless the index page has a specific group set. * - * We have this logic here because not all NavItem instances belong to sidebars, and we need data from both. + * We have this logic here because not all NavigationItem instances belong to sidebars, and we need data from both. */ public function isGroupActive(string $group): bool { diff --git a/packages/framework/src/Framework/Features/Navigation/NavigationItem.php b/packages/framework/src/Framework/Features/Navigation/NavigationItem.php index 1f3fd3ac784..833cd643406 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavigationItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavigationItem.php @@ -18,8 +18,8 @@ * * You have a few options to construct a navigation menu item: * 1. You can supply a Route directly and explicit properties to the constructor - * 2. You can use NavItem::fromRoute() to use data from the route - * 3. You can use NavItem::forLink() for an external or un-routed link + * 2. You can use NavigationItem::fromRoute() to use data from the route + * 3. You can use NavigationItem::forLink() for an external or un-routed link */ class NavigationItem implements Stringable { @@ -145,7 +145,7 @@ public function getGroupKey(): ?string } /** - * Check if the NavItem instance is the current page being rendered. + * Check if the NavigationItem instance is the current page being rendered. */ public function isActive(): bool { diff --git a/packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php b/packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php index 45914e47c63..e999c7922c7 100644 --- a/packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php +++ b/packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php @@ -1281,7 +1281,7 @@ protected function sidebar(?array $withPages = null): AssertableNavigationMenu } } -class TestNavItem +class TestNavigationItem { public readonly string $label; public readonly ?string $group; @@ -1319,12 +1319,12 @@ public function __construct(TestCase $test, $sidebar = false) /** A simplified serialized format for comparisons */ public function state(): array { - return $this->items->map(function (NavigationItem $item): TestNavItem { - return new TestNavItem($item->getLabel(), $item->getGroupKey(), $item->getPriority(), $item instanceof NavigationGroupItem ? $item->getItems() : []); + return $this->items->map(function (NavigationItem $item): TestNavigationItem { + return new TestNavigationItem($item->getLabel(), $item->getGroupKey(), $item->getPriority(), $item instanceof NavigationGroupItem ? $item->getItems() : []); })->toArray(); } - public function getState(int $index): ?TestNavItem + public function getState(int $index): ?TestNavigationItem { return $this->state()[$index] ?? null; } @@ -1345,7 +1345,7 @@ public function assertEquals(array $expected, bool $strict = false): static $item = ['label' => $item]; } - foreach (TestNavItem::properties() as $property) { + foreach (TestNavigationItem::properties() as $property) { if ($this->getState($index) !== null) { if (isset($item[$property])) { $a = $item[$property]; diff --git a/packages/framework/tests/Feature/NavigationMenuTest.php b/packages/framework/tests/Feature/NavigationMenuTest.php index 67f737964cc..bfe6d4a7435 100644 --- a/packages/framework/tests/Feature/NavigationMenuTest.php +++ b/packages/framework/tests/Feature/NavigationMenuTest.php @@ -29,7 +29,7 @@ public function testConstructor() $this->assertInstanceOf(MainNavigationMenu::class, $this->createNavigationMenu()); } - public function testGenerateMethodCreatesCollectionOfNavItems() + public function testGenerateMethodCreatesCollectionOfNavigationItems() { $this->assertInstanceOf(Collection::class, $this->createNavigationMenu()->getItems()); $this->assertContainsOnlyInstancesOf(NavigationItem::class, $this->createNavigationMenu()->getItems()); diff --git a/packages/framework/tests/Unit/NavGroupItemTest.php b/packages/framework/tests/Unit/NavGroupItemTest.php index 701c4041d18..c05034b072b 100644 --- a/packages/framework/tests/Unit/NavGroupItemTest.php +++ b/packages/framework/tests/Unit/NavGroupItemTest.php @@ -46,7 +46,7 @@ public function testDestinationIsAlwaysNull() public function testCanConstructWithChildren() { - $children = $this->createNavItems(); + $children = $this->createNavigationItems(); $item = new NavigationGroupItem('Foo', $children); $this->assertCount(2, $item->getItems()); @@ -55,7 +55,7 @@ public function testCanConstructWithChildren() public function testCanConstructWithChildrenWithoutRoute() { - $children = $this->createNavItems(); + $children = $this->createNavigationItems(); $item = new NavigationGroupItem('Foo', $children); $this->assertCount(2, $item->getItems()); @@ -64,7 +64,7 @@ public function testCanConstructWithChildrenWithoutRoute() public function testGetItems() { - $children = $this->createNavItems(); + $children = $this->createNavigationItems(); $item = new NavigationGroupItem('Foo', $children); $this->assertSame($children, $item->getItems()); @@ -94,7 +94,7 @@ public function testAddChildMethodReturnsSelf() public function testCanAddMultipleItemsToDropdown() { $group = new NavigationGroupItem('Foo'); - $items = $this->createNavItems(); + $items = $this->createNavigationItems(); $this->assertSame($items, $group->addItems($items)->getItems()); } @@ -197,7 +197,7 @@ public function testForLink() $this->assertSame(NavigationItem::class, $item::class); } - protected function createNavItems(): array + protected function createNavigationItems(): array { return [ new NavigationItem(new Route(new InMemoryPage('foo')), 'Foo'), diff --git a/packages/framework/tests/Unit/NavItemIsActiveHelperTest.php b/packages/framework/tests/Unit/NavigationItemIsActiveHelperTest.php similarity index 98% rename from packages/framework/tests/Unit/NavItemIsActiveHelperTest.php rename to packages/framework/tests/Unit/NavigationItemIsActiveHelperTest.php index 03f80fc7310..9e861f587a9 100644 --- a/packages/framework/tests/Unit/NavItemIsActiveHelperTest.php +++ b/packages/framework/tests/Unit/NavigationItemIsActiveHelperTest.php @@ -16,9 +16,9 @@ /** * @covers \Hyde\Framework\Features\Navigation\NavigationItem * - * @see \Hyde\Framework\Testing\Unit\NavItemTest + * @see \Hyde\Framework\Testing\Unit\NavigationItemTest */ -class NavItemIsActiveHelperTest extends UnitTestCase +class NavigationItemIsActiveHelperTest extends UnitTestCase { public static function setUpBeforeClass(): void { diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavigationItemTest.php similarity index 89% rename from packages/framework/tests/Unit/NavItemTest.php rename to packages/framework/tests/Unit/NavigationItemTest.php index 8d0ababf7d2..a76b0c0bbb5 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavigationItemTest.php @@ -17,14 +17,14 @@ use Mockery; /** - * This unit test covers the basics of the NavItem class. + * This unit test covers the basics of the NavigationItem class. * For the full feature test, see the MainNavigationMenuTest class. * * @covers \Hyde\Framework\Features\Navigation\NavigationItem * - * @see \Hyde\Framework\Testing\Unit\NavItemIsActiveHelperTest + * @see \Hyde\Framework\Testing\Unit\NavigationItemIsActiveHelperTest */ -class NavItemTest extends UnitTestCase +class NavigationItemTest extends UnitTestCase { public static function setUpBeforeClass(): void { @@ -79,33 +79,33 @@ public function testPassingUnknownRouteKeyToConstructorUsesExternalRoute() public function testGetDestination() { $route = new Route(new InMemoryPage('foo')); - $navItem = new NavigationItem($route, 'Page', 500); + $NavigationItem = new NavigationItem($route, 'Page', 500); - $this->assertSame($route, $navItem->getRoute()); + $this->assertSame($route, $NavigationItem->getRoute()); } public function testGetLink() { - $navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); - $this->assertSame('foo.html', $navItem->getUrl()); + $NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); + $this->assertSame('foo.html', $NavigationItem->getUrl()); } public function testGetLabel() { - $navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); - $this->assertSame('Page', $navItem->getLabel()); + $NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); + $this->assertSame('Page', $NavigationItem->getLabel()); } public function testGetPriority() { - $navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); - $this->assertSame(500, $navItem->getPriority()); + $NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); + $this->assertSame(500, $NavigationItem->getPriority()); } public function testGetGroup() { - $navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); - $this->assertNull($navItem->getGroupKey()); + $NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500); + $this->assertNull($NavigationItem->getGroupKey()); } public function testFromRoute() @@ -176,7 +176,7 @@ public function testForRouteWithCustomPriority() $this->assertSame(100, NavigationItem::forRoute(Routes::get('index'), 'foo', 100)->getPriority()); } - public function testRouteBasedNavItemDestinationsAreResolvedRelatively() + public function testRouteBasedNavigationItemDestinationsAreResolvedRelatively() { Render::swap(Mockery::mock(RenderData::class, [ 'getRoute' => new Route(new InMemoryPage('foo')),