-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Allow grid to use style variation blockGap values for columns calcula… #10906
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
base: trunk
Are you sure you want to change the base?
Allow grid to use style variation blockGap values for columns calcula… #10906
Conversation
|
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 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. |
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. |
| * @param array $registered_styles Currently registered block styles. | ||
| * | ||
| * @return string|null The name of the first registered variation, or null if none found. |
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.
| * @param array $registered_styles Currently registered block styles. | |
| * | |
| * @return string|null The name of the first registered variation, or null if none found. | |
| * @param array $registered_styles Currently registered block styles. | |
| * @return string|null The name of the first registered variation, or null if none found. |
Per document standard https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#1-functions-class-methods
| ) | ||
| ); | ||
|
|
||
| // WP_Theme_JSON_Resolver::clean_cached_data(); |
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.
Do we actually need this code here, or was it added by mistake?
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.
It was added in tear_down method so better to remove it from 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.
Ah, well spotted! I was experimenting and forgot to remove it 😅
| * Tests that block style variations with blockGap values are applied to layout styles. | ||
| * | ||
| * @ticket 64624 | ||
| * @covers ::wp_render_layout_support_flag |
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 test also cover wp_get_variation_name_from_class()? Then it should be added here too.
If not, another test should be added for it.
| 'type' => 'grid', | ||
| 'columnCount' => 3, | ||
| 'minimumColumnWidth' => '12rem', | ||
|
|
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.
| // Clean up. | ||
| remove_theme_support( 'appearance-tools' ); |
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 should go in tear_down, yeah?
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'm not sure. I'm seeing adding/removing of theme supports per test in most places, and the support is added inside the test so I thought I'd remove it there too. Though for this one I guess it won't make any difference practically, because it's removed at the end of the 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.
Actually thinking better about it, we shouldn't need appearance-tools support here at all!
| * @param string $class_name CSS class string for a block. | ||
| * @param array $registered_styles Currently registered block styles. |
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.
Can the array param be more specific? For example (if this is accurate):
| * @param string $class_name CSS class string for a block. | |
| * @param array $registered_styles Currently registered block styles. | |
| * @param string $class_name CSS class string for a block. | |
| * @param array<string, array<string, mixed>> $registered_styles Currently registered block styles. |
| $prefix = 'is-style-'; | ||
| $len = strlen( $prefix ); | ||
|
|
||
| foreach ( explode( ' ', $class_name ) as $class ) { | ||
| if ( str_starts_with( $class, $prefix ) ) { | ||
| $variation = substr( $class, $len ); |
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.
Best to not abbreviate the variable names:
| $prefix = 'is-style-'; | |
| $len = strlen( $prefix ); | |
| foreach ( explode( ' ', $class_name ) as $class ) { | |
| if ( str_starts_with( $class, $prefix ) ) { | |
| $variation = substr( $class, $len ); | |
| $prefix = 'is-style-'; | |
| $length = strlen( $prefix ); | |
| foreach ( explode( ' ', $class_name ) as $class ) { | |
| if ( str_starts_with( $class, $prefix ) ) { | |
| $variation = substr( $class, $length ); |
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.
+1
| * | ||
| * @return string|null The name of the first registered variation, or null if none found. | ||
| */ | ||
| function wp_get_variation_name_from_class( $class_name, $registered_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.
| function wp_get_variation_name_from_class( $class_name, $registered_styles = array() ) { | |
| function wp_get_variation_name_from_class( string $class_name, $registered_styles = array() ): ?string { |
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.
Just a couple of thoughts re: the new utility function (sorry I didn't catch this in the Gutenberg PR!):
- Would
wp_get_variation_name_from_classbe better placed inblock-style-variations.php? - There's an existing function
wp_get_block_style_variation_name_from_classthat accepts only a single param (class name). Would it be worth it to combine the logic into that existing function, with the optional second param? I.e. if the second param is empty, simply check against the classname, but if it's given a list of registered variations, then iterate over the list to find from the actual list of variations? - Alternately, still have this be a separate function, but give it consistent naming with the existing utility function, and co-locate it beside that function
Hope that all made sense, it's a useful function, though, and sounds like a good addition overall to me 👍
6d3822f to
54f1554
Compare
Yeah that's a good question. Also, it looks like Otherwise, I think we could consolidate the two functions into one. |
Oh, good point. Yeah, just as in Still, I don't mind the additional check (and the idea of adding it into the existing function via a second param) as it does give an additional polish of making sure that we're only looking up values that can exist. Up to you, I think, if you prefer the clarity or "correctness" of the additional check, or the simplicity of re-using the existing function. (Personally I think it's a valid choice either way). |
…tion
Trac ticket: https://core.trac.wordpress.org/ticket/64624
Syncs changes from WordPress/gutenberg#75360.
Use of AI Tools
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.