Skip to content
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

Section Styles: Clean up block style variation filters #62858

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jun 26, 2024

What?

Removes block style variation filters that were initially added to core for 6.6 but ultimately removed in WordPress/wordpress-develop#6873.

Why?

The functions don't exist and the filters are never ended up in core so there's nothing to remove in Gutenberg. The removal of the filters should have been removed before landing #62712.

How?

Delete lines.

Testing Instructions

  1. Defines block style variations via the different sources below:
    • register_block_style
    • Theme.json partial file under /styles directory including blockTypes
    • Within a theme style variation under styles.variations (must be registered via either of the above two methods)
      • Define a block style variation within a theme style variation following the example snippet below
      • It could be an override for a variation defined by register_block_style or theme.json partial in prior steps
      • Alternatively, simply register a block style using register_block_style, passing only the name and label in the style_properties array. This registration will mean the theme style variation's definition is not sanitized.
  2. Check that the block style variations still apply and are displayed correctly.
`register_block_style` Example
gutenberg_register_block_style(
	array( 'core/group', 'core/columns' ),
	array(
		'name'       => 'section-b',
		'label'      => __( 'Section B' ),
		'style_data' => array(
			'color'    => array(
				'background' => '#4f6f52',
				'text'       => '#d2e3c8',
			),
			'blocks'   => array(
				'core/group' => array(
					'color' => array(
						'background' => '#739072',
						'text'       => '#e3eedd',
					),
				),
			),
			'elements' => array(
				'link' => array(
					'color'  => array(
						'text' => '#ead196',
					),
					':hover' => array(
						'color' => array(
							'text' => '#ebd9b4',
						),
					),
				),
			),
		),
	)
);
Theme.json Partial Example
{
	"$schema": "https://schemas.wp.org/trunk/theme.json",
	"version": 3,
	"title": "Section A",
	"slug": "section-a",
	"blockTypes": [ "core/group" ],
	"styles": {
		"color": {
			"background": "slategrey",
			"text": "snow"
		},
		"blocks": {
			"core/group": {
				"color": {
					"background": "darkslategrey",
					"text": "whitesmoke"
				}
			}
		}
	}
}
Theme Style Variation Example (`styles.variations`)
{

	"styles": {
		"variations": {
			"section-a": {
				"color": {
					"background": "var(--wp--preset--color--theme-2)",
					"text": "var(--wp--preset--color--theme-5)"
				},
				"blocks": {
					"core/group": {
						"color": {
							"background": "var(--wp--preset--color--theme-4)",
							"text": "var(--wp--preset--color--theme-2)"
						}
					}
				}
			}
		}
	}
}

Alternatively, confirm that the removed filters don't exist in core and are safe to remove since WordPress/wordpress-develop#6873 was committed.

Screenshots or screencast

No visual changes.

@aaronrobertshaw aaronrobertshaw added [Type] Code Quality Issues or PRs that relate to code quality [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels Jun 26, 2024
@aaronrobertshaw aaronrobertshaw self-assigned this Jun 26, 2024
Copy link

github-actions bot commented Jun 26, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@aaronrobertshaw aaronrobertshaw added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json and removed [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks labels Jun 26, 2024
@ramonjd
Copy link
Member

ramonjd commented Jun 26, 2024

✅ Checked the deleted filters against the Core patch
register_block_style works as expected
✅ theme.json partial files work as expected

Theme Style Variation Example (styles.variations)

Could you remind me how to test this again?

@aaronrobertshaw
Copy link
Contributor Author

Could you remind me how to test this again?

Thanks for the quick review. I've tried updating the test instructions.

I'll try again here for good measure.

  1. Define a variation within your theme.json partial for a theme style variation e.g. Ember for TT4
  2. If the variation's key was my-custom-variation in the theme.json a block style needs to have been registered for that
    • This can happen automatically for you if a block style variation partial has the slug property my-custom-variation
    • Alternatively, you can register a block style passing just a name and label in the style properties
  3. In the site editor, switch to the theme style variation you've defined the block style variation in
  4. Check that it applies correctly
  5. Confirm the same in the post editor and frontend.
register_block_style(
	'core/group',
	array(
		'name'  => 'my-custom-variation',
		'label' => __( 'Custom' ),
	)
);
{
	...
	"styles": {
		"variations": {
			"my-custom-variation": {
				"color": {
					"background": "black",
					"text": "white"
				},
			}
		}
	}
}

@ramonjd
Copy link
Member

ramonjd commented Jun 26, 2024

If the variation's key was my-custom-variation in the theme.json a block style needs to have been registered for that

That's the bit I forgot. LGTM

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested all variants.
🚢

@aaronrobertshaw
Copy link
Contributor Author

That's the bit I forgot. LGTM

It was only a recent change to the way it all works so easily done!

Appreciate the repeated reviews on this one.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the variations of variations are testing well for me, too! 😄

@aaronrobertshaw aaronrobertshaw force-pushed the fix/clean-up-block-style-variation-filters branch from 7acdcef to 37ac727 Compare June 27, 2024 03:03
@aaronrobertshaw aaronrobertshaw enabled auto-merge (squash) June 27, 2024 03:38
@aaronrobertshaw aaronrobertshaw merged commit 12ee696 into trunk Jun 27, 2024
61 checks passed
@aaronrobertshaw aaronrobertshaw deleted the fix/clean-up-block-style-variation-filters branch June 27, 2024 03:39
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants