From 3b127a7a05da06546f2173ed0312df9c105a0a74 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Mon, 12 Apr 2021 18:06:54 -0700 Subject: [PATCH] Add generic InnerBlocks filter for allowed blocks --- .../src/components/inner-blocks/index.js | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index e826f3f9a1c52b..00b401ec77a810 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -10,6 +10,7 @@ import { useViewportMatch, useMergeRefs } from '@wordpress/compose'; import { forwardRef, useRef } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { getBlockType, withBlockContentContext } from '@wordpress/blocks'; +import { applyFilters } from '@wordpress/hooks'; /** * Internal dependencies @@ -49,21 +50,6 @@ function UncontrolledInnerBlocks( props ) { __experimentalLayout, } = props; - useNestedSettingsUpdate( - clientId, - allowedBlocks, - templateLock, - captureToolbars, - orientation - ); - - useInnerBlockTemplateSync( - clientId, - template, - templateLock, - templateInsertUpdatesSelection - ); - const context = useSelect( ( select ) => { const block = select( blockEditorStore ).getBlock( clientId ); @@ -78,6 +64,30 @@ function UncontrolledInnerBlocks( props ) { [ clientId ] ); + const FilteredAllowedBlocks = useSelect( ( select ) => { + const block = select( blockEditorStore ).getBlock( clientId ); + const blockFilterName = block.name.replace( '/', '-' ); + return applyFilters( + `editor.InnerBlocks.${ blockFilterName }.allowedBlocks`, + allowedBlocks + ); + } ); + + useNestedSettingsUpdate( + clientId, + FilteredAllowedBlocks, + templateLock, + captureToolbars, + orientation + ); + + useInnerBlockTemplateSync( + clientId, + template, + templateLock, + templateInsertUpdatesSelection + ); + // This component needs to always be synchronous as it's the one changing // the async mode depending on the block selection. return (