Open kimcoleman opened 1 year ago
Adding context here from our developer.
The problem seems to be rooted in the fact that the patterns use some custom blocks that are only registered for certain post types (llms-form and wp_block)
We need a way to register the blocks to be used within the context of the wp_block post type and still appear in the Site Editor / My Patterns context ( which isn't in the context of editing a wp_block post type ).
Are you able to provide any details about how you currently limit the registration of the blocks to specific post types?
Hey @glendaviesnz here's how: https://github.com/gocodebox/lifterlms-blocks/blob/trunk/src/js/blocks/index.js#L159-L161
Thanks!
Thanks for the extra detail @eri-trabiccolo, a couple of suggestions:
pagenow
registered which will be set to site-editor
when in the site editor context. Another option is to check for the presence of the site editor selectors.context
in the blocks edit methods to decide if you should render them in particular editor contexts. If you set the blocks to usesContext[postId, postType] in their block.json and then in the edit method do something like:
export default function MyBlock( {
context: { postType, postId },
} ) {
if ( postId && ! [ 'llms_form', 'wp_block' ].includes( postType )) {
return '<div>You are not able to use this block in this context</div>';
}
}
postType
and postId
will both be undefined in the context of the site editor patterns management page.
Get back to us if neither of those work for you and we can explore other options.
Hey @glendaviesnz
many thanks.
We considered to register the blocks by default and then use context
in the blocks edit methods to whether or not displaying the specific block, but we would prefer to not clutter the block lists that much.
I'm gonna try your solutions and decide what suits the best, because we actually need to register/edit some blocks from within some site templates as well (templates for the custom post types...).
Thanks again! <3
Description
In LifterLMS, we use reusable blocks (post type = wp_block) to allow admins to build reusable registration and profile form sections.
These can be edited within the LifterLMS > Forms admin screen, as well as via the admin wp_block post type list and editor. This would be for URLs like the following:
/wp-admin/edit.php?post_type=wp_block
No error for the LifterLMS reusable blocks./wp-admin/post.php?post=5&action=edit
No error for the LifterLMS reusable blocks.In the My Patterns screen (in WordPress 6.3), though, all of these reusable blocks (synced patterns) are returning an error. "Your site does not include support for the "llms/form-field-confirm-group" block.".
This is only in the editor.
We'd like a filter to exclude our patterns from displaying in this interface. Our developers have not found one available yet. We believe this is traced down to the fact that we limit the post types our reusable blocks can be inserted into. So a filter to exclude patterns there would be ideal.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
The post editor / block editor in the WP admin successfully allowing you to edit the synced pattern for LifterLMS form group.
The My Patterns screen in Site Editor that does not allow you to edit or recognize the synced pattern for LifterLMS form group.
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes