Make WordPress Core

Opened 13 months ago

Closed 10 months ago

Last modified 6 months ago

#57585 closed enhancement (fixed)

Editor: Make block type aware of selectors prop

Reported by: aaronrobertshaw's profile aaronrobertshaw Owned by: gziolo's profile gziolo
Milestone: 6.3 Priority: normal
Severity: normal Version: 6.2
Component: Editor Keywords: has-patch has-unit-tests needs-dev-note gutenberg-merge changes-requested
Focuses: Cc:

Description

In Gutenberg, an API was introduced to allow blocks to define custom CSS selectors for use in theme.json stylesheet generation. This was previously an experimental API contained within a block's block.json supports property.

It would be great to stabilize this API, making it a first-class citizen of the block.json schema. For this to occur, we must add selectors to the block type schema within core WP.

The original proposal regarding the selectors API can be found here:

The Gutenberg PR implementing the stabilized selectors API can be found here:

The new field should be included within the WP_Block_Type class, in the REST API endpoint for block types, and exposed in the get_block_editor_server_block_settings function.

Change History (18)

This ticket was mentioned in PR #3942 on WordPress/wordpress-develop by @aaronrobertshaw.


13 months ago
#1

  • Keywords has-patch has-unit-tests added

This PR adds support for the new selectors property. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function.

There is a corresponding Gutenberg PR (https://github.com/WordPress/gutenberg/pull/46496) that stabilizes the block.json selectors API and in part depends upon the changes here.

Trac ticket: https://core.trac.wordpress.org/ticket/57585

@gziolo commented on PR #3942:


13 months ago
#2

It's nearly ready from my perspective. I left my comments, and deciding on the default value is the only important thing.

#3 @gziolo
13 months ago

  • Keywords needs-dev-note commit added
  • Milestone changed from Awaiting Review to 6.3
  • Owner set to gziolo
  • Status changed from new to assigned

@aaronrobertshaw commented on PR #3942:


12 months ago
#4

@gziolo there have been a few changes here. I've added a second property to block types for editor-only selectors. Some background for this change can be found over on the related Gutenberg PR (https://github.com/WordPress/gutenberg/pull/46496#issuecomment-1464031044).

Essentially, we went with the second property to match the existing style / editorStyle block type properties, so we'll offer selectors / editorSelectors.

@gziolo commented on PR #3942:


12 months ago
#5

Essentially, we went with the second property to match the existing style / editorStyle block type properties, so we'll offer selectors / editorSelectors.

Sounds good, and the code changes look correct. I'm not sure why e2e tests failed on CI but I restarted the job to see if that was only an incident.

@aaronrobertshaw commented on PR #3942:


12 months ago
#6

I'm not sure why e2e tests failed on CI but I restarted the job to see if that was only an incident.

Seems like you had the magic touch 🪄

I'd already re-run it twice before rebasing the PR and having it fail again.

#7 @hellofromTonya
12 months ago

  • Keywords gutenberg-merge added

#8 @hellofromTonya
12 months ago

  • Keywords changes-requested added; commit removed

Some coding standards changes are requested on https://github.com/WordPress/wordpress-develop/pull/3942.

@aaronrobertshaw commented on PR #3942:


12 months ago
#9

👍 Thanks for the feedback @hellofromtonya. I believe I've addressed all of that now in https://github.com/WordPress/wordpress-develop/pull/3942/commits/82d1762b4bc5a9e8eaf114a58022f74302f7a973

@aaronrobertshaw commented on PR #3942:


12 months ago
#10

👍 Thanks for the feedback @hellofromtonya. I believe I've addressed all of that now in https://github.com/WordPress/wordpress-develop/pull/3942/commits/82d1762b4bc5a9e8eaf114a58022f74302f7a973

@aaronrobertshaw commented on PR #3942:


11 months ago
#11

There were some concerns raised around introducing support for editor-only selectors on the Gutenberg PR. For the time being, we'll remove that editor-only support so it can be discussed further and added at a future date.

As such, I've reverted the addition of editor selectors to block types here.

@gziolo commented on PR #3942:


11 months ago
#12

@aaronrobertshaw, it's been a while since all the changes landed in the Gutenberg plugin. Do you think it's good to go for WordPress core?

@aaronrobertshaw commented on PR #3942:


11 months ago
#13

Thanks for the nudge @gziolo!

After the removal of the editor-only selectors from this API, it doesn't seem like there is a great appetite yet to see them return. I suspect it might take some time to find solutions to the issues facing editor-only selectors.

Given that, I believe the changes here are stable and as you note the Selectors API landed in Gutenberg 15.5 so they've in the wild for a little while.

There's no objections from my end to see this land in core 🙂

#14 @gziolo
10 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 55673:

Editor: Add selectors field to block type definition

Adds support for the new selectors property for block types. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function.

Corresponding work in the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/46496.

Fixes #57585.
Props aaronrobertshaw, hellofromTonya.

#16 @stevenlinx
8 months ago

Do we have a volunteer to write the Dev Note for this ticket?
https://github.com/orgs/WordPress/projects/108/views/11

Thanks.

#17 @aaronrobertshaw
8 months ago

I've created a draft Dev Note here: https://make.wordpress.org/core/wp-admin/post.php?post=106203&action=edit

Unfortunately, I'll be AFK for a little over a week in the lead up to the 6.3 RC. Please feel free to edit, copy into a new post, or otherwise hack at that draft to get it into shape.

#18 @gziolo
6 months ago

In 56588:

Tests: Improve the assertions for REST API endpoint for block types

Follow-up to [56587], [55673]. While working on #59346, it was noted that selectors fiels is not always included in the assertions. While looking at it is was difficult to spot the issue because the random order of how REST API fields where listed.

Reorderd the REST API fields in the test cases to follow the list from the documentation: https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md. This way it's going to be easier to maintain the list moving forward.

Props ockham.
See #59346, #59313, #57585.

Note: See TracTickets for help on using tickets.