Section styles: consolidate variation name#62550
Conversation
|
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core GitHub repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json ❔ lib/block-supports/block-style-variations.php ❔ lib/class-wp-theme-json-gutenberg.php ❔ phpunit/block-supports/block-style-variations-test.php ❔ phpunit/class-wp-theme-json-resolver-test.php |
| * need to have their name set to the kebab case version of their title. | ||
| */ | ||
| $variation_name = $have_named_variations ? $key : _wp_to_kebab_case( $variation['title'] ); | ||
| $variation_name = $have_named_variations ? $key : ( $variation['slug'] ?? _wp_to_kebab_case( $variation['title'] ) ); |
There was a problem hiding this comment.
For most scenarios, just kebab-casing the title will be enough and that's a great devexp we may want to keep. The slug (could also use name) is a way to make it work for any scenario.
41808df to
c0cca63
Compare
The resolution of block style variations from partials needed to be tweaked in the same way the registration was so their key is consistent. I pushed a tweak in ebf2162 I'll give this a more thorough review shortly. Then create a backport PR, update the backport changelog etc. |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for putting this together @oandregal 👍
This tests well for me resolving both the "duplicate" style option and variation merging issues.
I've created a backport for the PHP changes and added a backport changelog entry to this PR.
|
Before we merge this one, we might need to update a couple of tests for the block style variations support and theme.json resolver. I'll sort those out on WordPress/wordpress-develop#6824 and then bring those back across to this PR. |
|
The unit test updates are pretty basic but cover:
|
|
It looks like tests have been failing on trunk since this merged and these changes look suspect. @aaronrobertshaw @oandregal have you noticed the test failures? Can you confirm whether they're related or not? |
|
The error does appear related, we'll look into it 👀 |
Co-authored-by: oandregal <oandregal@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
|
I just cherry-picked this PR to the wp/6.6-beta-3 branch to get it included in the next release: 7cfc6c5 |
Co-authored-by: oandregal <oandregal@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
What?
This PR enables theme.json partials to provide a different slug than the generated kebab-case to follow what any other registration mechanism (
block.json,register_style_variation) does.Why?
For theme.json partials to work like any other registration mechanism, and to enable them to override variations with names that don't follow the kebab-case convention.
The existing mechanisms to register block style variations require a
nameand alabel, see docs. Thenameis used to generate the associated class (e.g.:is-style-NAME) and we don't do any processing of it — all the following are correct:darkis-style-darkDarkis-style-DarkPitchDarkis-style-PitchDarkpitch-darkis-style-pitch-darkBefore this PR, the
titlefrom the theme.json partials was preprocessed to generate a kebab-cased variation name & class:darkdarkis-style-darkDarkdarkis-style-darkPitchDarkpitch-darkis-style-pitch-darkpitch-darkpitch-darkis-style-pitch-darkAfter this PR, the theme.json partials can contain an optional
slug(alternative:name?) key to be used in registering the variation and generating its class. This enables the theme.json partials to work with any variation name or class that wasn't kebab-case:darkdarkis-style-darkDarkDarkDarkis-style-DarkPitchDarkPitchDarkPitchDarkis-style-PitchDarkpitch-darkpitch-darkis-style-pitch-darkNote the
slugis optional and most of the cases will just lettitlebe kebab-cased.How?
Allow
slugto be provided in theme.json partials:slugif present, otherwise kebab-case thetitlea602aaeTesting Instructions
Register a variation with a non-kebab-cased name. For example, paste the following in the
functions.phpof TT4:styles/partial.jsonwith the following contents:{ "$schema": "https://schemas.wp.org/trunk/theme.json", "version": 2, "title": "My variation", "blockTypes": [ "core/group" ], "styles": { "color": { "background": "blue", "text": "white" } } }partial.jsonto include aslugthat matches the variation name provided byregister_block_stylecall:{ "$schema": "https://schemas.wp.org/trunk/theme.json", "version": 2, "title": "My variation", "slug": "MyVariation", "blockTypes": [ "core/group" ], "styles": { "color": { "background": "blue", "text": "white" } } }