Backport: Block template utils and rest templates controller#3221
Backport: Block template utils and rest templates controller#3221ntsekouras wants to merge 20 commits intoWordPress:trunkfrom
Conversation
a2b4a3a to
a3b7df7
Compare
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
|
edit: The GB PR has merged. |
ockham
left a comment
There was a problem hiding this comment.
Thank you, @ntsekouras! This LGTM; however, we need to wait for Gutenberg 14.1 (which is the first release to contain WordPress/gutenberg#44085) to be released before merging this PR. Otherwise, a WP install running Core trunk and Gutenberg stable will fatal because of the duplicate get_template_hierarchy definition.
hellofromtonya
left a comment
There was a problem hiding this comment.
First pass through the code. Most changes requested are for compliance to Core's coding / testing standards and/or for consistency.
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
|
@spacedmonkey Are you happy with the REST code in this PR? |
src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
Outdated
Show resolved
Hide resolved
| 'icon' => array( | ||
| 'description' => __( 'The icon for the post type.' ), | ||
| 'type' => 'string', | ||
| 'context' => array( 'view', 'edit', 'embed' ), |
There was a problem hiding this comment.
Does this need to be in the view context? The icon is not public right now?
There was a problem hiding this comment.
What do you mean public? I think it would be good to have in view as it can be useful in some cases. Do you see any drawback being in view context?
There was a problem hiding this comment.
If you make a property as view it means it can't be viewed pubilically. Do we want to expose this data publically?
There was a problem hiding this comment.
I see no harm in it, but if you have a strong opinion on this, I can remove it.
| } | ||
| $hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] ); | ||
| $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' ); | ||
| return rest_ensure_response( $fallback_template ); |
There was a problem hiding this comment.
| return rest_ensure_response( $fallback_template ); | |
| $response = $this->prepare_item_for_response( $fallback_template, $request ); | |
| return rest_ensure_response( $response ); |
Please ensure that response is run through prepare_item_for_response, so the response is formatted correctly.
There was a problem hiding this comment.
I'll update but this change will also need a GB PR(therefore a packages update) to retrieve the content from content.raw.
There was a problem hiding this comment.
Make the change and backport it. I can approve the change there as well. Change the properties / shape of response can / will cause problems down the road.
There was a problem hiding this comment.
GB PR is here: WordPress/gutenberg#44299 --cc @ockham
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
|
Thank you @spacedmonkey and @ntsekouras! Unfortunately, it seems like unit tests are failing: |
| } | ||
|
|
||
| if ( in_array( 'icon', $fields, true ) ) { | ||
| $data['icon'] = $post_type->menu_icon; |
There was a problem hiding this comment.
If this value is null, should it maybe default to something?
There was a problem hiding this comment.
I think it's okay to be null since it's not required and the consumers can decide what to do with it. For example in php core for post types we assign some default icon if it's in the admin menu, but in the site editor we assign different default icon..
|
Currently reviewing. When ready, will prep the commit. |
…troller.php Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
* Moved tests to its own test file. * Moved individual assertions to a data provider.
0bda281 to
5ba2daf
Compare
|
Rebased the branch on top of the latest |
After rebasing on top of trunk, the PR reverted some of the changes in wp-includes/block-template-utils.php that were added in changest 54184. This commit reapplies the code from that changeset. It also cleans up in one test.
hellofromtonya
left a comment
There was a problem hiding this comment.
LTGM 👍 Ready for commit, which I'm prepping next.
|
Note: The npm CI job failure is unrelated to this PR. |
|
Committed via changeset https://core.trac.wordpress.org/changeset/54269. Thank you everyone for your contributions! |
Trac ticket: https://core.trac.wordpress.org/ticket/56467
Backports changes from:
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.