-
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.
Merge pull request #35115 from Automattic/fix/remove-template-block-c…
…ontrols FSE: Remove template block settings and UI
- Loading branch information
Showing
7 changed files
with
130 additions
and
94 deletions.
There are no files selected for viewing
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
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
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
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
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 a template block, deselect it. | ||
// Note: this does not work for post content because you can't | ||
// edit inner blocks if the outer block is deselected. | ||
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
Oops, something went wrong.