-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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]: Add REST API endpoint to fetch variations #38124
Conversation
lib/compat/wordpress-6.0/class-gutenberg-rest-global-styles-controller.php
Outdated
Show resolved
Hide resolved
44dba5f
to
362774f
Compare
…ntroller.php Co-authored-by: George Mamadashvili <[email protected]>
array( | ||
array( | ||
'methods' => WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'get_theme_items' ), |
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 we should rename get_theme_items
to get_theme_variations
or change the endpoint to be theme-items
. This all comes down to whether we want to support more things from this endpoint other than fetching the variations.
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.
We will merge this into WP_REST_Global_Styles_Controller
in the future, right? In that case using get_theme_variations
or get_variation_items
make sense.
In order to properly test this, I can see three options:
I'm not really familiar with php tests, so I could use some feedback. |
It would be helpful for e2e tests as well. We also have two other themes, especially for PHPUnit tests; you can also use them. |
Actually this sounds better, yes. We will have e2e tests later on. |
|
||
if ( rest_is_field_included( 'styles', $fields ) ) { | ||
$raw_data = $theme->get_raw_data(); | ||
$data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array(); |
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.
This in core is $theme->get_raw_data()['styles'];
assuming that every theme.json
has styles
property. We'll need to backport to core. What I'm wondering though should we set this to empty array or not set at all? @oandregal , @jorgefilipecosta
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.
Core patch here: WordPress/wordpress-develop#2224
@@ -0,0 +1,23 @@ | |||
{ |
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.
Nit: I wonder if we should try to make the variation more "meaningful". For instance add a "dark" variation to the empty theme.
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 can do it an a follow up to unblock the remaining functionality from landing. I'd appreciate if some theme dev could provide a minimal dark
theme.json for empty theme. --cc @kjellr 🙏
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.
Hmm. So this would be just for the emptytheme
version bundled here with Gutenberg, right? For the canonical version over in theme-experiments, I don't think adding a style makes sense since it's positioned primarily as an ultra-minimal starting point.
It doesn't even specify a color palette, so making a dark mode version of it is a bit unexpected. 😄
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.
LGTM 👍
Part of: #35619
In this PR the REST API endpoint is being extracted from the main above PR.
As noted in the original PR about
WP_REST_Global_Styles_Controller
: