Skip to content

Commit

Permalink
[Site Editor]: Set html block as freeform fallback block (#48129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored Feb 23, 2023
1 parent 987a6c7 commit 26e00a8
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { store as blocksStore } from '@wordpress/blocks';
import {
registerCoreBlocks,
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { dispatch } from '@wordpress/data';
Expand All @@ -16,7 +17,6 @@ import {
import { store as editorStore } from '@wordpress/editor';
import { store as interfaceStore } from '@wordpress/interface';
import { store as preferencesStore } from '@wordpress/preferences';
import { addFilter } from '@wordpress/hooks';
import { registerLegacyWidgetBlock } from '@wordpress/widgets';

/**
Expand All @@ -41,32 +41,17 @@ export function initializeEditor( id, settings ) {
settings.__experimentalFetchRichUrlData = fetchUrlData;

dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
registerCoreBlocks();
const coreBlocks = __experimentalGetCoreBlocks().filter(
( { name } ) => name !== 'core/freeform'
);
registerCoreBlocks( coreBlocks );
dispatch( blocksStore ).setFreeformFallbackBlockName( 'core/html' );
registerLegacyWidgetBlock( { inserter: false } );
if ( process.env.IS_GUTENBERG_PLUGIN ) {
__experimentalRegisterExperimentalCoreBlocks( {
enableFSEBlocks: true,
} );
}
/*
* Prevent adding the Clasic block in the site editor.
* Only add the filter when the site editor is initialized, not imported.
* Also only add the filter(s) after registerCoreBlocks()
* so that common filters in the block library are not overwritten.
*
* This usage here is inspired by previous usage of the filter in the post editor:
* https://github.com/WordPress/gutenberg/pull/37157
*/
addFilter(
'blockEditor.__unstableCanInsertBlockType',
'removeClassicBlockFromInserter',
( canInsert, blockType ) => {
if ( blockType.name === 'core/freeform' ) {
return false;
}
return canInsert;
}
);

// We dispatch actions and update the store synchronously before rendering
// so that we won't trigger unnecessary re-renders with useEffect.
Expand Down

1 comment on commit 26e00a8

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 26e00a8.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4253705447
📝 Reported issues:

Please sign in to comment.