Skip to content

Commit

Permalink
Hide the Classic block in the Site Editor (#44554)
Browse files Browse the repository at this point in the history
* Hide the classic block using a filter

* Update the comment wording
  • Loading branch information
michalczaplinski committed Oct 3, 2022
1 parent 9d1fe96 commit 7e9fd39
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
import { __ } from '@wordpress/i18n';
import { store as viewportStore } from '@wordpress/viewport';
import { getQueryArgs } from '@wordpress/url';
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -51,6 +52,26 @@ export function reinitializeEditor( target, settings ) {
return;
}

/*
* 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;
}
);

// This will be a no-op if the target doesn't have any React nodes.
unmountComponentAtNode( target );
const reboot = reinitializeEditor.bind( null, target, settings );
Expand Down

0 comments on commit 7e9fd39

Please sign in to comment.