-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Global styles controllers: extend with WP_REST_Posts_Controller and WP_REST_Revisions_Controller #5699
Conversation
1e43217
to
1428167
Compare
222463e
to
7e40ac4
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
7e40ac4
to
4ffbee2
Compare
@adamsilverstein No huge rush, but if you get a chance to take this for a test drive, I'd be very grateful 🙇🏻 |
I double checked and the failing E2E test is also failing on trunk: [[chromium] › gutenberg-plugin.test.js:25:6 › Gutenberg plugin › should activate: tests/e2e/specs/gutenberg-plugin.test.js#L12](https://github.com/WordPress/wordpress-develop/pull/5699/files#annotation_16570999825)
1) [chromium] › gutenberg-plugin.test.js:25:6 › Gutenberg plugin › should activate ───────────────
Retry #1 ───────────────────────────────────────────────────────────────────────────────────────
SyntaxError: Unexpected token '<', "<br />
<b>"... is not valid JSON
10 | test.beforeAll( async ( { requestUtils } ) => {
11 | // Install Gutenberg plugin if it's not yet installed.
> 12 | const pluginsMap = await requestUtils.getPluginsMap();
| ^
13 | if ( ! pluginsMap.gutenberg ) {
14 | await requestUtils.rest( {
15 | method: 'POST', |
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
Outdated
Show resolved
Hide resolved
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.
Let's leave the unit tests and not delete them.
One issue here is the revisions controller currently guesses that the parent controller is a instance or sub class of post controller. Means means it expects some classes and properties that might not exist in WP_REST_Global_Styles_Controller
.
tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php
Show resolved
Hide resolved
edc8162
to
1120502
Compare
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.
My biggest worry about this WP_REST_Global_Styles_Controller
does not extend the WP_REST_Posts_Controller
. Future refactors would might meaning breaks here, as class methods / properties do not match. I feel like if we are going to make this change, we go the whole way and convert WP_REST_Global_Styles_Controller
to extend WP_REST_Posts_Controller
. Then we can use the work done in 1f51e1f, to regsiter custom post / revision controllers when registering the global post type. Then this manaul regsiteration can be removed here.
wordpress-develop/src/wp-includes/rest-api.php
Lines 326 to 332 in 43d2455
// Global Styles revisions. | |
$controller = new WP_REST_Global_Styles_Revisions_Controller(); | |
$controller->register_routes(); | |
// Global Styles. | |
$controller = new WP_REST_Global_Styles_Controller(); | |
$controller->register_routes(); |
Thanks for the feedback. Looks like this point was raised by @TimothyBJacobs back when the endpoint was introduced: WordPress/gutenberg#35801 (review)
@TimothyBJacobs do you think this is still the case? The "custom" nature of global styles, I think, still stands. I'm happy to take a stab at it if we think inheriting |
The big difference is now 1f51e1f is committed, we can make custom revisions endpoints. I think now we can have custom revisions, it register this as a post endpoint and revisions endpoint. Let's try this change in another PR, see if it makes sense. |
1120502
to
2275567
Compare
Started here. More stuff and tests to come 👍🏻 |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Works pretty well over at #6008, but I'm wondering if registering endpoints should also be optional - e.g., Global styles should be able to opt out of autosaves routes Perhaps explicitly setting Ora a I'm happy to get a PR up to test this out. |
Closing in favour of #6022 |
@spacedmonkey Just checking, this PR was working as a stand alone patch. Did you close with the intention to port these changes over to #6022? Otherwise I think we should reopen. |
@ramonjd I thought we were aligned on #6022? I feel like #6022 is good to commit. |
Definitely, but just not sure why this PR needed to be closed? I think maybe our wires just got crossed 😅 This PR affects Happy to reapprove #6022 - it's good to go, but we still need this PR I think. |
WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Controller
…ted from WP_REST_Revisions_Controller tests
…-revisions-controller.php Co-authored-by: Mukesh Panchal <[email protected]>
Excluding order and order by from the collection query params Comment
… individual items.
d4d7e82
to
bf20794
Compare
Updating generated API file
bf20794
to
dac8e0b
Compare
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 believe the contractor, get_item and update_item methods no longer need to be overridden in the global style controller.
I also had a note about marking this endpoint as not support batching.
I love this change, as it allows the gutenberg plugin to override these classes easier.
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
Show resolved
Hide resolved
removing __construct, get_item and update_item in favour of the parent class methods Add $allow_batch property, setting it to false
👍🏻 Done What do you think about The functions are the identical, the only difference being the error message, which seems fairly samey. $error = new WP_Error(
'rest_global_styles_not_found',
__( 'No global styles config exist with that id.' ),
array( 'status' => 404 )
); In post controller: $error = new WP_Error(
'rest_post_invalid_id',
__( 'Invalid post ID.' ),
array( 'status' => 404 )
); |
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.
Looks good to me
@@ -457,10 +382,10 @@ protected function prepare_links( $id ) { | |||
* | |||
* @return array List of link relations. | |||
*/ | |||
protected function get_available_actions() { | |||
protected function get_available_actions( $post, $request ) { |
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.
Missing @param
documentation for new variables.
$this->rest_base = 'revisions'; | ||
$this->parent_base = 'global-styles'; | ||
$this->namespace = 'wp/v2'; | ||
public function __construct( $parent_post_type ) { |
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.
Missing @param
documentation for new variables.
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
Show resolved
Hide resolved
Co-authored-by: Jonny Harris <[email protected]>
@@ -454,13 +379,16 @@ protected function prepare_links( $id ) { | |||
* | |||
* @since 5.9.0 | |||
* @since 6.2.0 Added 'edit-css' action. | |||
* @since 6.5.0 Add $post and $request parameters. |
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.
* @since 6.5.0 Add $post and $request parameters. | |
* @since 6.5.0 Added $post and $request parameters. |
Committed. |
This change:
WP_REST_Global_Styles_Revisions_Controller
withWP_REST_Revisions_Controller
WP_REST_Global_Styles_Controller
withWP_REST_Posts_Controller
As part of this work, the PR also:
Trac ticket: https://core.trac.wordpress.org/ticket/60131
Related PRs/discussions
get_item
but we'll still need the single revision route)