Page taxonomies - #778
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the system from a hardcoded "tags" feature to a more flexible "taxonomy" system, enabling support for multiple taxonomy types beyond just tags.
- Introduces a generic taxonomy system to replace the hardcoded tags functionality
- Updates data structure from flat
tagsfield to nestedtaxonomy.tagstructure - Adds route constraints to validate taxonomy types against configured site taxonomies
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| site/templates/partials/tags.php | Updates template to use taxonomy.tag instead of tags field |
| site/templates/controllers/blog.php | Refactors filtering logic to use new havingTaxonomy() method with generic taxonomy parameters |
| site/schemes/pages/post.yaml | Updates schema field definition from tags to taxonomy.tag |
| site/pages/*/post.md | Migrates content data structure from flat tags to nested taxonomy.tag format |
| formwork/src/Schemes/SchemeFactory.php | Adds deprecation warning for allowTags option with automatic migration to allowTaxonomy |
| formwork/src/Router/Router.php | Implements constraint checking for route parameters with support for closures and arrays |
| formwork/src/Router/Route.php | Adds where() method and constraint storage for route parameter validation |
| formwork/src/Pages/PageCollection.php | Implements havingTaxonomy() method for filtering pages by taxonomy terms |
| formwork/src/Pages/Page.php | Adds taxonomy() getter and setTaxonomy() setter with validation |
| formwork/src/Controllers/PageController.php | Updates taxonomy route validation from tagName to taxonomy parameter |
| formwork/config/site.yaml | Defines available taxonomies configuration |
| formwork/config/routes/routes.php | Updates routes from tag/tagName to taxonomy/taxonomyTerm with constraint validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function setTaxonomy(array $taxonomy): void | ||
| { | ||
| if (!Arr::every($taxonomy, fn($terms, $taxonomyName) => is_string($taxonomyName) | ||
| && is_array($terms) && Arr::every($terms, fn($term) => is_string($term)))) { | ||
| throw new InvalidValueException('Invalid taxonomy format'); | ||
| } |
There was a problem hiding this comment.
The method throws InvalidValueException but lacks a @throws annotation in its docblock. Add @throws InvalidValueException to document this behavior.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request refactors the handling of tags in the Formwork CMS to support a more flexible taxonomy system. Tags are now treated as a type of taxonomy, enabling future support for additional taxonomies beyond just tags. The changes include updates to routes, data structures, filtering logic, and deprecation notices, ensuring backward compatibility and extensibility.
Taxonomy system introduction and migration
routes.php, allowing for filtering and pagination by any taxonomy defined in the site config.taxonomystructure instead oftags, and adjusted templates to display taxonomy terms. [1] [2] [3] [4] [5] [6]Core data model and API changes
taxonomysupport to thePageclass, including getter and setter methods with validation, and included taxonomy in page defaults. [1] [2]havingTaxonomymethod inPageCollectionto filter pages by taxonomy terms, supporting both plain and slug matching.Routing engine enhancements
Deprecation and compatibility
allowTagsscheme option in favor ofallowTaxonomy, with a deprecation warning, and updated code to check for the new option. [1] [2]Configuration updates
taxonomiesentry to the site configuration, initializing it withtagfor backward compatibility and future extensibility.