admin管理员组文章数量:1410724
I have a post type which is prepopulated with a Gutenberg block:
function blog_block_template() {
$post_type_event = get_post_type_object( 'event' );
$post_type_event->template = array(
array( 'acf/single-event-meta' ),
);
}
add_action( 'init', 'blog_block_template' );
This certain block should not be deleted or reordered. I don’t want to use a meta box because the meta box would be rendered below all Gutenberg blocks or on the side which would be confusing for the user.
There’s the supports
parameter when registering a Gutenberg block which allows to restrict some functionality but I couldn’t find anything about deleting or reordering.
'supports' => array(
'align' => false,
'customClassName' => false,
'html' => false,
'inserter' => false,
'multiple' => false,
'reusable' => false,
),
Thanks!
I have a post type which is prepopulated with a Gutenberg block:
function blog_block_template() {
$post_type_event = get_post_type_object( 'event' );
$post_type_event->template = array(
array( 'acf/single-event-meta' ),
);
}
add_action( 'init', 'blog_block_template' );
This certain block should not be deleted or reordered. I don’t want to use a meta box because the meta box would be rendered below all Gutenberg blocks or on the side which would be confusing for the user.
There’s the supports
parameter when registering a Gutenberg block which allows to restrict some functionality but I couldn’t find anything about deleting or reordering.
'supports' => array(
'align' => false,
'customClassName' => false,
'html' => false,
'inserter' => false,
'multiple' => false,
'reusable' => false,
),
Thanks!
Share Improve this question edited Jan 28, 2020 at 11:03 user1706680 asked Jan 28, 2020 at 10:26 user1706680user1706680 6943 gold badges13 silver badges29 bronze badges 2- Some more context would be helpful in identifying a solution, what's the problem that this solves for you? – Tom J Nowell ♦ Commented Jan 28, 2020 at 10:33
- Thanks for asking. I added some context. I hope that clarifies. – user1706680 Commented Jan 28, 2020 at 10:37
1 Answer
Reset to default 1You could use a block template.
For any given post type, you can set up a block template which adds blocks to the Editor whenever you create a new post of that type. These templates have an option called template_lock
which you can set to all
which means that users cannot add, move, or delete any blocks.
Of course you probably want to let people add other blocks - but you can still use a template. You would need to create your own wrapper block, one that holds your event block inside of it - and that also allows InnerBlocks
. This way, your wrapper with its event will always be required, but people can still add, edit, move, and delete any other blocks on the page as needed.
本文标签: Gutenberg – How to prevent block from being deleted and reorderedmoved
版权声明:本文标题:Gutenberg – How to prevent block from being deleted and reorderedmoved 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744796100a2625583.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论