Skip to content

Commit

Permalink
[Merl-786] post_type_supports -> use_block_editor_for_post_type (#…
Browse files Browse the repository at this point in the history
…120)

* Fix: use `use_block_editor_for_post_type` instead of `post_type_supports`

* Tests: Add unit test for `use_block_editor_for_post_type`

* Update odd-files-attend.md

* Update .changeset/odd-files-attend.md

Co-authored-by: Blake Wilson <[email protected]>

---------

Co-authored-by: Blake Wilson <[email protected]>
  • Loading branch information
theodesp and blakewilson authored Oct 10, 2023
1 parent 1415e91 commit 7251fb0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-files-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wpengine/wp-graphql-content-blocks": major
---

Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types.
**BREAKING**: Potential schema changes on previously exposed blocks that do not support the block editor. Those blocks will no longer inherit the `editorBlocks` field.
3 changes: 1 addition & 2 deletions includes/Utilities/WPHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public static function get_supported_post_types(): array {
if ( empty( $block_editor_post_types ) || ! is_array( $block_editor_post_types ) ) {
return $supported_post_types;
}

// Iterate over the post types
foreach ( $block_editor_post_types as $block_editor_post_type ) {
// If the post type doesn't support the editor, it's not block-editor enabled
if ( ! post_type_supports( $block_editor_post_type->name, 'editor' ) ) {
if ( ! use_block_editor_for_post_type( $block_editor_post_type->name ) ) {
continue;
}

Expand Down
36 changes: 36 additions & 0 deletions tests/unit/RegistryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@ interfaces {
$this->assertTrue( in_array( $contains_interface, $response['data']['__type']['interfaces'] ) );
}

/**
* This test ensures that when disabling the block editor for post types then
* no additional interfaces are included in them.
*/
public function test_no_additional_interfaces_on_block_editor_disabled_block_types() {
add_filter('use_block_editor_for_post_type', '__return_false');
$query = '
query GetType($name:String!) {
__type(name: $name) {
interfaces {
name
}
}
}
';

$this->instance->init();

// Verify the response contains what we put in cache
$response = graphql(
array(
'query' => $query,
'variables' => array(
'name' => 'Post',
),
)
);
$not_included = array(
'name' => 'NodeWithEditorBlocks',
);
$this->assertArrayHasKey( 'data', $response, json_encode( $response ) );
$this->assertNotEmpty( $response['data']['__type']['interfaces'] );
$this->assertNotContains( $not_included, $response['data']['__type']['interfaces'] );
remove_filter('use_block_editor_for_post_type', '__return_false');
}

/**
* This test ensures that the `register_interface_types()` method
* works as expected when the get_allowed_block_types is used
Expand Down

0 comments on commit 7251fb0

Please sign in to comment.