-
Notifications
You must be signed in to change notification settings - Fork 4.6k
contentOnly patterns: mark patterns as contentOnly by adding metadata.patternName to the root block (patterns endpoint) #73375
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
Conversation
- Introduced `Gutenberg_REST_Block_Patterns_Controller_7_0` to handle block patterns via the REST API. - Registered new REST API routes for block patterns in WordPress 7.0. - Updated existing files to include the new controller and ensure proper functionality. - Added unit tests for pattern block resolution in REST API responses.
|
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. |
| ), | ||
| 'schema' => array( $this, 'get_public_item_schema' ), | ||
| ), | ||
| true // Override the core route. |
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 is required to ensure this controller's routes take precedence
| $this->assertSame( | ||
| '<!-- wp:paragraph {"metadata":{"patternName":"test/single-block-pattern-1","name":"Single Block Pattern 1","description":"A single block pattern 1.","categories":["text"]}} -->Single block pattern 1 content<!-- /wp:paragraph --><!-- wp:paragraph {"metadata":{"patternName":"test/single-block-pattern-2","name":"Single Block Pattern 2","description":"A single block pattern 2."}} -->Single block pattern 2 content<!-- /wp:paragraph -->', | ||
| $nested_pattern['content'], | ||
| 'Sibling patterns pattern should contain the two resolved patterns.' | ||
| ); |
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.
Note that it doesn't yet consider other children.
What if we have a pattern that contains the following:
<!-- wp:pattern...
<!--wp:heading...
<!--wp:paragraph...Should they be grouped?
Maybe we need to wrap all patterns that don't have a single root block?
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.
There are definitely some edge cases, but I think this PR helps get us to about 99% (at least of the core patterns) working well.
Perhaps we can keep the issue open to discuss the edge cases.
We can also publish a dev note to help educate theme/pattern devs about making compliant patterns.
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.
Good ideas, thanks for testing this PR!
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.
We can also publish a dev note to help educate theme/pattern devs about making compliant patterns.
I'll add this note to the documentation issue: #71572
…ller for WordPress 7.0
talldan
left a comment
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.
Thanks, this works well for me, and solves the most pressing issue!
What? How?
Partly addresses #73262
Follow up to #72988
This PR extends
WP_REST_Block_Patterns_Controllerso that it can callgutenberg_resolve_pattern_blocks, which was introduced in #72988WP_REST_Block_Patterns_Controllercalls resolve_pattern_blocks here in Core.Why?
Some patterns comprise other patterns, e.g., see TT5's page templates
Sibling patterns should be parsed.
Before
After
Testing Instructions
Fire up this PR and enable the content only experiment.
Open a new page or post and insert of the page patterns mentioned above.
The patterns within those patterns should be parsed, and therefore, they'll be in "content only" mode in the editor.
You'll be able to tell because the list view will show the pattern icons, and the block inspector will show their editable fields.
Screenshots or screencast
Kapture.2025-11-18.at.15.16.17.mp4