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

[Merl-786] post_type_supports -> use_block_editor_for_post_type #120

Merged
merged 4 commits into from
Oct 10, 2023

Conversation

theodesp
Copy link
Member

@theodesp theodesp commented Jun 21, 2023

Description

Replaces the post_type_supports with use_block_editor_for_post_type when resolving the get_supported_post_types. This has the added benefit of running the use_block_editor_for_post_type hook that was missed, potentially including blocks that dont work with the block editor.

Tasks

  • Has automated tests confirming schema accuracy on post types that support blocks and post types that do not support blocks.
  • Has been tested with WPGraphQL for WooCommerce
  • Has been tested with WPGraphQL for ACF (existing and new)
  • Has a changeset

Closes #27

@theodesp theodesp requested a review from a team as a code owner June 21, 2023 16:56
@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2023

🦋 Changeset detected

Latest commit: c5bedba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wpengine/wp-graphql-content-blocks Major

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

@mindctrl
Copy link
Contributor

Let's get some tests that confirm the schema is correct for post types that do and do not support blocks.

@jasonbahl
Copy link
Contributor

@theodesp any updates on when this might be released?

I'm trying to use WPGraphQL Content Blocks + ACF Blocks, and anytime I register a block to be available on only one specific post type, I am seeing it exposed to the Schema on all post types, which is not ideal.

@jasonbahl
Copy link
Contributor

I'm trying to use WPGraphQL Content Blocks + ACF Blocks, and anytime I register a block to be available on only one specific post type, I am seeing it exposed to the Schema on all post types, which is not ideal.

Ah, I think I'm running into a different, but related issue.

If I register a a block and set it to only be exposed to a single post type, it still implements the interfaces for all post types.

For example, I've registered a block that is only available on the "Post" post type.

But it gets the following interfaces applied to it:

CleanShot 2023-08-17 at 10 57 51

And it can be queried on any post type, not just the Post Post Type.

I would expect a Block registered to just one Post Type to have the Interface for that Post Type implemented. In my case, I would expect PostEditorBlock to be implemented but not EventEditorBlock, PageEditorBlock, etc.

@jasonbahl
Copy link
Contributor

Update:

I think what I'm doing is a bit custom and not necessarily expected to be working.

I'm using ACF Extended which provides a way to register block types and constrain which post types the block type should be available on.

The Blocks registered with constraints are still being exposed in WPGraphQL Content Blocks to all post types via Registry->get_block_context_interfaces( $block_name )

This is because ACF Extended adds a post_types => [] configuration to each block type, but this isn't actually something supported by core Gutenberg (yet, at least as far as I can tell: WordPress/gutenberg#9855 (comment))

So, because this is added functionality of ACF Extended, there's no reasonable expectation WPGraphQL Content Blocks would have supported this.

I'll open a new issue and corresponding PR to add a filter so 3rd parties can hook in and customize some of the logic.

I'm supporting ACF Extended Fields in WPGraphQL for ACF and since I'm also working on supporting ACF Blocks + WPGraphQL Content Blocks in that codebase, I would like to filter this logic so things play nice, but I'll need a filter to exist.

@jasonbahl
Copy link
Contributor

I opened an issue (#147) and PR (#148) to help with the situation I was facing. 🙏🏻

@theodesp
Copy link
Member Author

theodesp commented Oct 2, 2023

Check with with WPGraphQL for WooCommerce

Created one product:

Screenshot 2023-10-02 at 13 45 27

@theodesp
Copy link
Member Author

theodesp commented Oct 2, 2023

Check with with [wp-graphql-acf] old and new.

Created one block:
Screenshot 2023-10-02 at 14 39 09

@theodesp
Copy link
Member Author

theodesp commented Oct 4, 2023

Using add_filter('use_block_editor_for_post_type', '__return_false');

Screenshot 2023-10-04 at 11 44 56

the editorBlocks field is not registered

Copy link
Contributor

@mindctrl mindctrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Would be nice to have tests that confirm the desired behavior.

@jasonbahl
Copy link
Contributor

One thing to note:

This will cause breaking changes to the Schema on any site that updates.

@theodesp theodesp requested a review from mindctrl October 10, 2023 09:19
@theodesp theodesp requested a review from blakewilson October 10, 2023 15:33
@theodesp theodesp merged commit 7251fb0 into main Oct 10, 2023
@theodesp theodesp deleted the MERL-786 branch October 10, 2023 16:08
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.

blocks are being exposed to all post types, even those that don't use Gutenberg
5 participants