Normalize data structure by removing dots when merging defaults and frontmatter - #786
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves how nested data structures are handled in page content and configuration by expanding dotted keys into proper nested arrays and switching to recursive array merging for more robust handling of nested values.
Key Changes
- Applies
Arr::undot()to frontmatter and defaults to convert dotted keys (e.g.,metadata.title) into nested arrays (e.g.,['metadata' => ['title' => ...]]) - Replaces array spread operator with
array_replace_recursive()for merging data, which preserves nested values that aren't explicitly overridden
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| formwork/src/Pages/ContentFile.php | Adds Arr::undot() to convert dotted keys in YAML frontmatter to nested arrays |
| formwork/src/Pages/Page.php | Updates data merging to use array_replace_recursive() and applies Arr::undot() to defaults for consistent nested structure handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request introduces improvements to how nested data structures are handled in page content and configuration files by ensuring that "dotted" keys are properly expanded into nested arrays. The changes primarily focus on using the
Arr::undot()utility to convert flattened arrays into nested ones, which helps maintain correct data structure throughout the application. Additionally, the logic for merging data arrays has been updated to usearray_replace_recursivefor more robust handling of nested values.Improvements to nested data handling:
formwork/src/Pages/ContentFile.php: Now usesArr::undot()to convert dotted keys in frontmatter to nested arrays when loading content files, ensuring correct data structure. [1] [2]formwork/src/Pages/Page.php: Returns undotted (nested) defaults in thedefaults()method by applyingArr::undot().Enhancements to array merging logic:
formwork/src/Pages/Page.php: Usesarray_replace_recursiveinstead of array spread for merging defaults and content file frontmatter into the page data, which improves handling of nested arrays and prevents overwriting nested values. [1] [2]