-
Notifications
You must be signed in to change notification settings - Fork 15
Replace core/block with core/synced-pattern (Changes GraphQL response structure) #347
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 7cffce7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
$this->assertArrayHasKey( 'slug', $actual[0]['attrs'] ); | ||
|
||
$this->assertEquals( 'core/columns', $actual[1]['blockName'] ); | ||
$this->assertCount( 4, $actual ); |
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 now count the 'synced pattern` block as well.
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.
LGTM 🎉
cc @justlevine |
I hope to take a look at this shortly. |
@justlevine were you able to take a look as well please? |
Not yet @theodesp - I've been traveling for rtCamp's annual company retreat - but it's on my to-do list for first thing next Monday when I'm back at my desk 🤞 |
$registry = \WP_Block_Type_Registry::get_instance(); | ||
$block_name = 'core/synced-pattern'; | ||
|
||
if ( ! $registry->is_registered( $block_name ) ) { |
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 seems very fragile and maybe also unnecessary?
Instead I would recommend reusing CoreBlock
by renaming it in GraphQL to CoreSyncedPattern
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.
@justlevine How can we rename an existing block in GraphQL? I'm not familiar with this.
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.
@justlevine how should we handle the mapping in GraphQL to reflect core/synced-pattern without re-registering it?
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.
Pseudocode:
add_filter( 'graphql_type_name', static function( $type_name ) {
// Bail if not our Block. (str_starts_with() would probably be too loose).
if ( 'CoreBlock' !== $type_name && 'CoreBlockAttributes' !== $type_name ) { return $type_name; }
// or to whatever you're calling it.
return str_replace( 'CoreBlock', 'CoreSyncedPatternBlock', $type_name );
} );
Or you could probably use includes/Block/CoreBlock.php
to intercept and overload the default registration.
Description:
core/block
withcore/synced-pattern
, based on WP 6.3's changes to reusable blocksBreaking Change Notice:
For WP < 6.3: The plugin remains functional, but GraphQL responses now return core/synced-pattern instead of returning a list of innerBlocks of that pattern
Previously, the response directly returned the inner blocks of the reusable pattern directly, stripping all the information about the
core/block
type:Now, the reusable block is wrapped inside core/synced-pattern,
Reference
#345 #345
How to Test the Changes
Go to Appearance > Editor (or Design > Patterns in WP 6.3+).
Click Manage all patterns and then Add New Pattern.
Ensure "Synced" is enabled before saving.
Create or edit a post.
Add a new block and select the synced pattern you just created.
Save the post.
Run the following GraphQL query to fetch the blocks in the post:
Expected result:
The core/synced-pattern block is returned as the parent, with its inner blocks nested inside it. The parentClientId of the inner blocks should reference the core/synced-pattern block.
Example response: