[DRAFT] Templates / DataViews: Show declared post types for templates #76020
Draft
Mayank-Tripathi32 wants to merge 3 commits into
Draft
[DRAFT] Templates / DataViews: Show declared post types for templates #76020Mayank-Tripathi32 wants to merge 3 commits into
Mayank-Tripathi32 wants to merge 3 commits into
Conversation
Add `post_types` field to the templates REST API schema and response. The field returns an array of post type slugs that can use the template, based on the `postTypes` property defined in theme.json. - Add `post_types` property to REST API schema for templates and static templates controllers - Populate `post_types` field in template responses from template file data - Add Post Types column to templates table view in Site Editor - Include post_types in default
This reverts commit 290bf9c. Remove `post_types` field from templates REST API schema and template building logic. This removes the `post_types` property from the static templates controller schema and stops populating the field when building template objects from files.
84bb886 to
6b5b019
Compare
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.
Closes #75670 (Still WIP exploration)
What?
Closes
Adds a Post Types column to the Templates DataViews list, showing which post types each template is associated with (as defined via
postTypesintheme.jsoncustom templates).Why?
Template
postTypesdata is already defined intheme.jsonand used internally for filtering, but it was never exposed in the REST API or surfaced in the Site Editor's template list UI. This makes it difficult for users to see at a glance which templates are available for which post types.How?
WIP - Needs discussion on proper way we could get this backported.
Gutenberg_REST_Templates_Controller_7_0: Addedpost_typestoprepare_item_for_response()— returns the template'spost_typesarray (or an empty array if not set). Addedget_item_schema()to registerpost_typesas a readonly array-of-strings field.Gutenberg_REST_Static_Templates_Controller: Extendedget_item_schema()to include the samepost_typesproperty for the registered-templates endpoint.template-activate.php: After building a template from file via_build_block_template_result_from_file(), thepostTypesdata from the theme file is now propagated onto the template object so it's available for serialization.Testing Instructions
postTypesin itstheme.json(e.g., a theme with entries like"postTypes": ["post"]or"postTypes": ["post", "page"]undercustomTemplates).postTypesdefined should show the types as a comma-separated list (e.g.,postorpost, page).postTypesdefined should show an em dash (—).postTypeson its custom templates.Testing via REST API
/wp/v2/templates(or/wp/v2/registered-templates).post_typesfield.postTypesin theme.json should return the array (e.g.,["post"]).postTypesshould return an empty array ([]).Testing Instructions for Keyboard
Screenshots
Table View
Grid View
List View