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

Try: Render variation alias blocks (set canonical name early) #6594

Draft
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented May 21, 2024

This is a variation (no pun intended) of @tjcafferkey's #6555. It's the same commits, but cut off after 52d6b3d -- i.e. with no changes to the WP_Block_Type and WP_Block_Type_Registry classes. Instead, the canonical block name is extracted early on during instantiation of the WP_Block instance, and used to interact with those other classes.

This seems to be working for me:

image

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.

@ockham ockham self-assigned this May 21, 2024
@ockham ockham changed the title Try/render variations set canonical block name early Try: Render variation alias blocks (set canonical name early) May 21, 2024
@ockham
Copy link
Contributor Author

ockham commented May 21, 2024

As @tjcafferkey pointed out to me in DM, the fact that we're getting the wp-social-link-wordpress class name is due to the Social Link block (rather than a more generic mechanism):

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ),
			'style' => block_core_social_link_get_color_styles( $block->context ),
		)
	);

So we can't rely on that for other blocks. Instead, we will have to generate the class name for the block variation.

@ockham
Copy link
Contributor Author

ockham commented May 21, 2024

I've just pushed d7735f8 which is one attempt at solving the problem. It infers the block variation name based on the strategy described in WordPress/gutenberg#43743 (comment).

This seems to work alright, but only for blocks whose variations are registered on the server side. Examples are the Template Part or Navigation Link blocks. (The Social Link block sadly isn't.)

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants