diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json index 494214858bf422..02c2084dabb3f4 100644 --- a/packages/block-library/src/column/block.json +++ b/packages/block-library/src/column/block.json @@ -11,6 +11,9 @@ }, "width": { "type": "string" + }, + "templateLock": { + "type": "string" } }, "supports": { diff --git a/packages/block-library/src/column/edit.js b/packages/block-library/src/column/edit.js index 70e1e669bf5118..aedf4e7270550c 100644 --- a/packages/block-library/src/column/edit.js +++ b/packages/block-library/src/column/edit.js @@ -22,7 +22,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; function ColumnEdit( { - attributes: { verticalAlignment, width }, + attributes: { verticalAlignment, width, templateLock = false }, setAttributes, clientId, } ) { @@ -60,7 +60,7 @@ function ColumnEdit( { style: width ? { flexBasis: width } : undefined, } ); const innerBlocksProps = useInnerBlocksProps( blockProps, { - templateLock: false, + templateLock, renderAppender: hasChildBlocks ? undefined : InnerBlocks.ButtonBlockAppender, diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index f554f5ca01b559..6014985192acfe 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -6,6 +6,9 @@ "tagName": { "type": "string", "default": "div" + }, + "templateLock": { + "type": "string" } }, "supports": { diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index ecf56d13f73dc1..9920b05c334b56 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -20,12 +20,13 @@ function GroupEdit( { attributes, clientId } ) { [ clientId ] ); const blockProps = useBlockProps(); - const { tagName: TagName = 'div' } = attributes; + const { tagName: TagName = 'div', templateLock } = attributes; const innerBlocksProps = useInnerBlocksProps( { className: 'wp-block-group__inner-container', }, { + templateLock, renderAppender: hasInnerBlocks ? undefined : InnerBlocks.ButtonBlockAppender, diff --git a/packages/e2e-tests/plugins/cpt-locking.php b/packages/e2e-tests/plugins/cpt-locking.php index 8889d8a25267fd..f4fbdb99ffb25e 100644 --- a/packages/e2e-tests/plugins/cpt-locking.php +++ b/packages/e2e-tests/plugins/cpt-locking.php @@ -52,6 +52,82 @@ function gutenberg_test_cpt_locking() { 'template_lock' => false, ) ); + register_post_type( + 'l-post-ul-group', + array( + 'public' => true, + 'label' => 'Locked Post Unlocked group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array( + 'templateLock' => false, + ), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); + register_post_type( + 'l-post-l-group', + array( + 'public' => true, + 'label' => 'Locked Post Locked group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array( + 'templateLock' => 'all', + ), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); + register_post_type( + 'l-post-i-group', + array( + 'public' => true, + 'label' => 'Locked Post Inherited group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array(), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); } add_action( 'init', 'gutenberg_test_cpt_locking' ); diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap index 157989c0da728a..bec98aa0820550 100644 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap @@ -36,6 +36,26 @@ exports[`cpt locking template_lock all should not error when deleting the cotent " `; +exports[`cpt locking template_lock all unlocked group should allow blocks to be moved 1`] = ` +" +
+

p1

+ + + +

+
+" +`; + +exports[`cpt locking template_lock all unlocked group should allow blocks to be removed 1`] = ` +" +
+

+
+" +`; + exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = ` "
\\"\\"/
diff --git a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js index e4f62ca47aeb36..59bb45283fca58 100644 --- a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js +++ b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js @@ -180,4 +180,67 @@ describe( 'cpt locking', () => { it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); } ); + + describe( 'template_lock all unlocked group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'l-post-ul-group', + } ); + } ); + + it( 'should allow blocks to be removed', async () => { + await page.type( + '.block-editor-rich-text__editable[data-type="core/paragraph"]', + 'p1' + ); + await clickBlockToolbarButton( 'More options' ); + const [ removeBlock ] = await page.$x( + '//button[contains(text(), "Remove block")]' + ); + await removeBlock.click(); + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + + it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); + } ); + + describe( 'template_lock all locked group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'l-post-l-group', + } ); + } ); + + it( + 'should not allow blocks to be removed', + shouldNotAllowBlocksToBeRemoved + ); + + it( 'should not allow blocks to be moved', async () => { + await page.click( + '.block-editor-rich-text__editable[data-type="core/paragraph"]' + ); + expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull(); + } ); + } ); + + describe( 'template_lock all inherited group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'l-post-i-group', + } ); + } ); + + it( + 'should not allow blocks to be removed', + shouldNotAllowBlocksToBeRemoved + ); + + it( 'should not allow blocks to be moved', async () => { + await page.click( + '.block-editor-rich-text__editable[data-type="core/paragraph"]' + ); + expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull(); + } ); + } ); } );