[6.x] Add default sorting support for taxonomies#14772
Open
finnjsmith wants to merge 1 commit into
Open
Conversation
…nd `sort_dir` fields
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.
Docs issue: statamic/docs#1925
Add sort_by and sort_dir support to Taxonomies
What & Why
Collections support
sort_byandsort_dirconfig options to control the default sort field and direction in the CP listing. Taxonomies havesortField()andsortDirection()methods on the model but they are hardcoded to return'title'and'asc'respectively, both marked with// todocomments, and neither key is read from or written to the taxonomy's YAML file.This means there is currently no way to configure the default sort order of a taxonomy's term listing in the CP.
Changes
src/Taxonomies/Taxonomy.php— replaced hardcodedsortField()andsortDirection()methods with fluent getter/setter implementations (mirroringCollection.php), addedprotected $sortFieldandprotected $sortDirectionproperties, and updatedfileData()to persistsort_byandsort_dir.src/Stache/Stores/TaxonomiesStore.php— updatedmakeItemFromFile()to hydratesort_byandsort_dirfrom the taxonomy YAML (mirroringCollectionsStore.php).Usage
Notes
There is no UI for this, which is consistent with how Collections handle it — it's a developer-facing config option. The behaviour is otherwise identical to Collections.