-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable selection of template blocks
This means that you can't see any reference to their settings! Note that we cannot do this same patch for the post content block because once the block has been disabled, you can't edit the inner blocks. Will have to find a different patch for that.
- Loading branch information
1 parent
e5ed9c4
commit 20e8c2f
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...editing/full-site-editing-plugin/full-site-editing/editor/disable-block-settings/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* global fullSiteEditing */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { select, dispatch, subscribe } from '@wordpress/data'; | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* Removes the block settings panel if the template or post content blocks are selected. | ||
* Since it is not possible to disable the block settings entirely through Gutenberg state, | ||
* we use a hack to deselect the block, which removes the option to change its settings. | ||
* This is also done officially in the core PostTitle block, so there is prior art. | ||
* | ||
* @see https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-title/index.js | ||
*/ | ||
const unsubscribe = subscribe( () => { | ||
// We don't care about this on the template or post editor | ||
if ( 'page' !== fullSiteEditing.editorPostType ) { | ||
return unsubscribe(); | ||
} | ||
|
||
// Determine which block we have selected: | ||
const selectedBlock = select( 'core/editor' ).getSelectedBlock(); | ||
const blockName = get( selectedBlock, 'name', null ); | ||
|
||
// If we have selected one the template block, deselect it. | ||
// Note: this does not work for post content because you can't | ||
// edit inner blocks if the block is not selected. | ||
if ( 'a8c/template' === blockName ) { | ||
dispatch( 'core/block-editor' ).clearSelectedBlock( blockName ); | ||
} | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters