Skip to content

Commit

Permalink
Disable "FSE" blocks in Widgets Editor (#32761)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
getdave authored and youknowriad committed Jun 24, 2021
1 parent c3f3fed commit 942fe13
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
18 changes: 14 additions & 4 deletions packages/customize-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,30 @@ 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.
*
* @param {string} editorName The editor name.
* @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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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' ),
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-widgets/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ALLOW_REUSABLE_BLOCKS = false;
export const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false;
27 changes: 23 additions & 4 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
<Layout blockEditorSettings={ settings } />,
document.getElementById( id )
Expand Down

0 comments on commit 942fe13

Please sign in to comment.