2

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!

2
  • Some more context would be helpful in identifying a solution, what's the problem that this solves for you?
    – Tom J Nowell
    Jan 28, 2020 at 10:33
  • Thanks for asking. I added some context. I hope that clarifies. Jan 28, 2020 at 10:37

1 Answer 1

1

You 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.