Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable "FSE" blocks in Widgets Editor #32761

Merged
merged 7 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, store as coreStore } 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( coreStore ).getEntityRecords(
'postType',
'wp_block'
),
reusableBlocks: ALLOW_REUSABLE_BLOCKS
? select( coreStore ).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' ] ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@getdave this does not work if we set ALLOW_REUSABLE_BLOCKS to true as the expression will return false which is not iterable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. Fix available for review #34634

];

/**
* 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