22 * Internal dependencies
33 */
44import previewImage from './images/preview.jpg'
5- import { i18n , srcUrl } from 'stackable'
5+ import {
6+ i18n ,
7+ srcUrl ,
8+ settings ,
9+ } from 'stackable'
610import {
711 Button ,
812 ModalDesignLibrary ,
@@ -11,7 +15,7 @@ import { SVGStackableIcon } from '~stackable/icons'
1115import {
1216 deprecateBlockBackgroundColorOpacity , deprecateContainerBackgroundColorOpacity , deprecateTypographyGradientColor ,
1317} from '~stackable/block-components'
14- import { substituteCoreIfDisabled } from '~stackable/util'
18+ import { substituteCoreIfDisabled , BLOCK_STATE } from '~stackable/util'
1519import { substitutionRules } from '../../blocks'
1620
1721/**
@@ -29,14 +33,30 @@ import { useBlockProps } from '@wordpress/block-editor'
2933
3034// Replaces the current block with a block made out of attributes.
3135const createBlockWithAttributes = ( blockName , attributes , innerBlocks , design ) => {
36+ const disabledBlocks = settings . stackable_block_states || { } // eslint-disable-line camelcase
37+ const nonSubstitutableBlocks = new Set ( )
38+
3239 // Recursively substitute core blocks to disabled Stackable blocks
3340 const traverseBlocksAndSubstitute = blocks => {
3441 return blocks . map ( block => {
3542 let [ blockName , blockAttributes , innerBlocks ] = block
43+
3644 if ( innerBlocks && innerBlocks . length > 0 ) {
3745 innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
3846 }
47+
3948 const substituted = substituteCoreIfDisabled ( blockName , blockAttributes , innerBlocks , substitutionRules )
49+ const blockType = getBlockType ( blockName )
50+
51+ // Get the disabled non-substitutable blocks
52+ if ( ! ( blockName in substitutionRules ) &&
53+ ( ! blockType || blockType [ 'stk-cannot-be-disabled' ] !== true ) &&
54+ blockName in disabledBlocks &&
55+ disabledBlocks [ blockName ] === BLOCK_STATE . DISABLED
56+ ) {
57+ nonSubstitutableBlocks . add ( blockName )
58+ }
59+
4060 if ( ! Array . isArray ( substituted [ 2 ] ) ) {
4161 substituted [ 2 ] = [ ]
4262 }
@@ -45,6 +65,17 @@ const createBlockWithAttributes = ( blockName, attributes, innerBlocks, design )
4565 }
4666
4767 innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
68+
69+ // Warn the user which blocks are needed to be enabled
70+ if ( nonSubstitutableBlocks . size > 0 ) {
71+ // eslint-disable no-console
72+ console . warn ( // eslint-disable-line no-console
73+ `The selected design requires the following block(s) to be enabled for it to function properly:\n\n` +
74+ `${ Array . from ( nonSubstitutableBlocks ) . join ( '\n' ) } `
75+ )
76+ // eslint-enable no-console
77+ }
78+
4879 // const { replaceBlock } = dispatch( 'core/block-editor' )
4980
5081 // For wireframes, we'll need to apply any default block attributes to
0 commit comments