From 942fe1384c394d8516f3204e9feb1d1ef34c0b17 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 24 Jun 2021 10:25:33 +0100 Subject: [PATCH] Disable "FSE" blocks in Widgets Editor (#32761) * Disable post-* and query* blocks * Disable remaining entity blocks and any experimental FSE blocks * Apply same disabling in the Customizer Widgets screen * Remove any registered reusable blocks from inserter * Fully disable reusable blocks in Widgets Editor * Fully disable reusable blocks in Widgets Editor * Improve constant usage --- packages/customize-widgets/src/index.js | 18 ++++++++++--- .../index.js | 8 +++--- packages/edit-widgets/src/constants.js | 2 ++ packages/edit-widgets/src/index.js | 27 ++++++++++++++++--- 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 packages/edit-widgets/src/constants.js diff --git a/packages/customize-widgets/src/index.js b/packages/customize-widgets/src/index.js index 475629450f8609..bf3b8eef0c8622 100644 --- a/packages/customize-widgets/src/index.js +++ b/packages/customize-widgets/src/index.js @@ -22,6 +22,9 @@ import './filters'; const { wp } = window; +const DISABLED_BLOCKS = [ 'core/more', 'core/block', 'core/freeform' ]; +const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false; + /** * Initializes the widgets block editor in the customizer. * @@ -29,13 +32,20 @@ const { wp } = window; * @param {Object} blockEditorSettings Block editor settings. */ export function initialize( editorName, blockEditorSettings ) { - const coreBlocks = __experimentalGetCoreBlocks().filter( - ( block ) => ! [ 'core/more', 'core/freeform' ].includes( block.name ) - ); + const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => { + return ! ( + DISABLED_BLOCKS.includes( block.name ) || + block.name.startsWith( 'core/post' ) || + block.name.startsWith( 'core/query' ) || + block.name.startsWith( 'core/site' ) + ); + } ); registerCoreBlocks( coreBlocks ); registerLegacyWidgetBlock(); if ( process.env.GUTENBERG_PHASE === 2 ) { - __experimentalRegisterExperimentalCoreBlocks(); + __experimentalRegisterExperimentalCoreBlocks( { + enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS, + } ); } registerLegacyWidgetVariations( blockEditorSettings ); diff --git a/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js b/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js index 63244ffaf9be3a..c94754ba5bf431 100644 --- a/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js +++ b/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js @@ -24,6 +24,7 @@ import { useEntityBlockEditor } from '@wordpress/core-data'; import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../../store/utils'; import useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area'; import { store as editWidgetsStore } from '../../store'; +import { ALLOW_REUSABLE_BLOCKS } from '../../constants'; export default function WidgetAreasBlockEditorProvider( { blockEditorSettings, @@ -43,10 +44,9 @@ export default function WidgetAreasBlockEditorProvider( { ), widgetAreas: select( editWidgetsStore ).getWidgetAreas(), widgets: select( editWidgetsStore ).getWidgets(), - reusableBlocks: select( 'core' ).getEntityRecords( - 'postType', - 'wp_block' - ), + reusableBlocks: ALLOW_REUSABLE_BLOCKS + ? select( 'core' ).getEntityRecords( 'postType', 'wp_block' ) + : [], isFixedToolbarActive: select( editWidgetsStore ).__unstableIsFeatureActive( 'fixedToolbar' ), diff --git a/packages/edit-widgets/src/constants.js b/packages/edit-widgets/src/constants.js new file mode 100644 index 00000000000000..c2ab518c5c9c4a --- /dev/null +++ b/packages/edit-widgets/src/constants.js @@ -0,0 +1,2 @@ +export const ALLOW_REUSABLE_BLOCKS = false; +export const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false; diff --git a/packages/edit-widgets/src/index.js b/packages/edit-widgets/src/index.js index f2e98fc62b5a2c..7ed910113e7e8f 100644 --- a/packages/edit-widgets/src/index.js +++ b/packages/edit-widgets/src/index.js @@ -24,6 +24,16 @@ import './store'; import './filters'; import * as widgetArea from './blocks/widget-area'; import Layout from './components/layout'; +import { + ALLOW_REUSABLE_BLOCKS, + ENABLE_EXPERIMENTAL_FSE_BLOCKS, +} from './constants'; + +const disabledBlocks = [ + 'core/more', + 'core/freeform', + ...( ! ALLOW_REUSABLE_BLOCKS && [ 'core/block' ] ), +]; /** * Initializes the block editor in the widgets screen. @@ -32,18 +42,27 @@ import Layout from './components/layout'; * @param {Object} settings Block editor settings. */ export function initialize( id, settings ) { - const coreBlocks = __experimentalGetCoreBlocks().filter( - ( block ) => ! [ 'core/more', 'core/freeform' ].includes( block.name ) - ); + const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => { + return ! ( + disabledBlocks.includes( block.name ) || + block.name.startsWith( 'core/post' ) || + block.name.startsWith( 'core/query' ) || + block.name.startsWith( 'core/site' ) + ); + } ); + registerCoreBlocks( coreBlocks ); registerLegacyWidgetBlock(); if ( process.env.GUTENBERG_PHASE === 2 ) { - __experimentalRegisterExperimentalCoreBlocks(); + __experimentalRegisterExperimentalCoreBlocks( { + enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS, + } ); } registerLegacyWidgetVariations( settings ); registerBlock( widgetArea ); settings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) => fetchLinkSuggestions( search, searchOptions, settings ); + render( , document.getElementById( id )