generateblocks
generateblocks copied to clipboard
Block templates not respecting "template_lock" when using generateblocks blocks
Description
I am setting up block templates for custom post types, as described here in the handbook: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/
When I use core blocks in the template and the 'template_lock' argument is set to all, blocks cannot be moved, deleted or new ones added. However, when I use generateblocks blocks in the template and the 'template_lock' argument is set to all, it still allows to move and add blocks.
Steps to reproduce
Assign a block template to to a post type (in the example, to 'post'):
<?php
function ls_register_template() {
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = $block_template;
$post_type_object->template_lock = 'all';
}
add_action( 'init', 'ls_register_template' );
example of block_template with core blocks:
$block_template = [
[
'core/group',
[],
[
[
'core/heading',
[
'level' => 2,
'content' => 'Example Block Template',
]
],
[
'core/paragraph',
[
'content' => 'Lorem ipsum dolor sit amet labore cras venenatis.',
]
],
[
'core/columns',
[],
[
[
'core/column',
[],
[
[
'core/heading',
[
'level' => 3,
'content' => 'Sub Heading 1',
]
],
[
'core/paragraph',
[
'content' => 'Lorem ipsum dolor sit amet id erat aliquet diam ullamcorper tempus massa eleifend vivamus.',
]
],
]
],
[
'core/column',
[],
[
[
'core/heading',
[
'level' => 3,
'content' => 'Sub Heading 2',
]
],
[
'core/paragraph',
[
'content' => 'Morbi augue cursus quam pulvinar eget volutpat suspendisse dictumst mattis id.',
]
],
]
],
],
],
]
]
];
example of block_template with generateblocks blocks:
$block_template = [
[
'generateblocks/container',
[
'tagName' => 'h2',
'isDynamic' => true,
],
[
[
'generateblocks/grid',
[
'columns' => 2,
'isDynamic' => true,
'verticalAlignment' => 'flex-start',
'horizontalAlignment' => 'center',
],
[
[
'generateblocks/container',
[
'isGrid' => true,
'width' => 50,
'widthTablet' => 90,
'widthMobile' => 100,
'isDynamic' => true,
],
[
[
'generateblocks/headline',
[
'element' => 'h2',
'placeholder' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
],
]
]
],
[
'generateblocks/container',
[
'isGrid' => true,
'width' => 50,
'widthTablet' => 100,
'widthMobile' => 100,
'isDynamic' => true,
],
[
[
'generateblocks/headline',
[
'element' => 'p',
'placeholder' => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. ',
],
]
]
],
],
],
]
],
];
Expected behavior
I was expecting blocks in the template to be locked when using generateblocks blocks, as it happens with core blocks.
Actual behavior
Generateblocks blocks do not respect the 'template_lock'
References:
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/
p.s.: $block_template is declared inside the function, I have put it in the message separately only for clarity..
We have a new filter in 1.7.0 (https://github.com/tomusborne/generateblocks/tree/release/1.7.0) that might fix this: generateblocks.editor.containerTemplateLock
By default our Container block has templateLock set to false, but this filter opens it up to changes.