feat: section#27
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new section concept to the navigation library so consumers can organize navigation items into top-level structural containers alongside the existing collapsible groups.
Changes:
- Adds
Item::section(),nav_section(), andNavigationBuilder::section()to create section nodes in config, helpers, and runtime registration. - Adds validation and exception messaging intended to prevent sections from being nested under sections or groups.
- Documents the new feature in the README and adds unit tests covering section creation, rendering, helper usage, and some invalid nesting cases.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/SectionsTest.php | Adds section-focused unit tests for builders, helpers, rendering, and invalid nesting. |
| src/helpers.php | Introduces the nav_section() helper and updates group helper docs. |
| src/NavigationBuilder.php | Adds runtime builder support for registering sections. |
| src/ItemBuilder.php | Adds the new Item::section() factory and section metadata defaults. |
| src/Exceptions/InvalidNavigationItemException.php | Adds a dedicated exception factory for invalid nested sections. |
| src/Data/NavigationItem.php | Extends validation to reject some nested section configurations. |
| README.md | Documents sections, helper usage, builder usage, nesting rules, and output shape. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+194
to
+205
| // Sections cannot be nested inside sections or groups | ||
| $isSection = ! empty($data['section']); | ||
| $isGroup = ! empty($data['group']); | ||
|
|
||
| if (($isSection || $isGroup) && isset($data['children']) && is_array($data['children'])) { | ||
| foreach ($data['children'] as $child) { | ||
| if ($child instanceof ItemBuilder) { | ||
| $child = $child->toArray(); | ||
| } | ||
|
|
||
| if (is_array($child) && ! empty($child['section'])) { | ||
| throw InvalidNavigationItemException::nestedSection($data, $isSection ? 'section' : 'group'); |
Comment on lines
+148
to
+156
| public static function section(string $label, array $children = []): static | ||
| { | ||
| $item = new static($label); | ||
| $item->meta['section'] = true; | ||
| $item->meta['collapsible'] = false; | ||
| $item->meta['collapsed'] = false; | ||
| $item->children = $children; | ||
|
|
||
| return $item; |
| InvalidNavigationItemException::class, | ||
| 'Navigation sections cannot be nested inside a group.' | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.