Skip to content

Page taxonomies - #778

Merged
giuscris merged 7 commits into
2.xfrom
fature/taxonomies
Nov 15, 2025
Merged

Page taxonomies#778
giuscris merged 7 commits into
2.xfrom
fature/taxonomies

Conversation

@giuscris

@giuscris giuscris commented Nov 6, 2025

Copy link
Copy Markdown
Member

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

  • Replaced the old tag-specific routes and logic with generic taxonomy-based routes in routes.php, allowing for filtering and pagination by any taxonomy defined in the site config.
  • Updated post metadata in markdown files and page schemes to use the new taxonomy structure instead of tags, and adjusted templates to display taxonomy terms. [1] [2] [3] [4] [5] [6]

Core data model and API changes

  • Added taxonomy support to the Page class, including getter and setter methods with validation, and included taxonomy in page defaults. [1] [2]
  • Implemented a new havingTaxonomy method in PageCollection to filter pages by taxonomy terms, supporting both plain and slug matching.

Routing engine enhancements

  • Added parameter constraints to the routing system, allowing routes to validate taxonomy names against those defined in the site configuration, and ensured constraints are checked during dispatch. [1] [2] [3] [4]

Deprecation and compatibility

  • Deprecated the allowTags scheme option in favor of allowTaxonomy, with a deprecation warning, and updated code to check for the new option. [1] [2]

Configuration updates

  • Added a taxonomies entry to the site configuration, initializing it with tag for backward compatibility and future extensibility.

@giuscris
giuscris requested a review from Copilot November 6, 2025 21:42
@giuscris giuscris self-assigned this Nov 6, 2025
@giuscris giuscris added the enhancement New feature or request label Nov 6, 2025
@giuscris
giuscris marked this pull request as draft November 6, 2025 21:43
@giuscris giuscris added this to the 2.2.0 milestone Nov 6, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 tags field to nested taxonomy.tag structure
  • 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.

Comment thread formwork/src/Pages/PageCollection.php
Comment thread formwork/src/Pages/PageCollection.php
Comment on lines +405 to +410
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');
}

Copilot AI Nov 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method throws InvalidValueException but lacks a @throws annotation in its docblock. Add @throws InvalidValueException to document this behavior.

Copilot uses AI. Check for mistakes.
@giuscris
giuscris marked this pull request as ready for review November 15, 2025 12:04
@giuscris
giuscris requested a review from Copilot November 15, 2025 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@giuscris
giuscris merged commit 10a2e50 into 2.x Nov 15, 2025
7 checks passed
@giuscris
giuscris deleted the fature/taxonomies branch November 15, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants