-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport: Block template utils and rest templates controller #3221
Backport: Block template utils and rest templates controller #3221
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be in the view context? The icon is not public right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
|
@@ -221,6 +221,10 @@ public function prepare_item_for_response( $item, $request ) { | |||
$data['slug'] = $post_type->name; | |||
} | |||
|
|||
if ( in_array( 'icon', $fields, true ) ) { | |||
$data['icon'] = $post_type->menu_icon; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this value is null, should it maybe default to something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.