Skip to content

Commit 40862e2

Browse files
committed
fix: move disabling of block outside the registration
1 parent a442c52 commit 40862e2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/blocks.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import './disabled-blocks'
1212
/**
1313
* External dependencies
1414
*/
15-
import { i18n } from 'stackable'
15+
import {
16+
i18n,
17+
settings as stackableSettings,
18+
} from 'stackable'
1619
import {
1720
addStackableBlockCategory,
1821
registerBlockType,
22+
BLOCK_STATE,
1923
} from '~stackable/util'
2024
import { withVisualGuideContext } from '~stackable/higher-order'
2125

@@ -50,7 +54,13 @@ const importAllAndRegister = r => {
5054

5155
// Register the block if it's not already registered and not disabled.
5256
if ( ! getBlockType( name ) ) {
53-
registerBlockType( name, settings )
57+
// Register the block if the block is not disabled.
58+
if ( ! ( ( settings[ 'stk-block-dependency' ] in stackableSettings.stackable_block_states &&
59+
stackableSettings.stackable_block_states[ settings[ 'stk-block-dependency' ] ] === BLOCK_STATE.DISABLED ) ||
60+
stackableSettings.stackable_block_states[ name ] === BLOCK_STATE.DISABLED
61+
) ) {
62+
registerBlockType( name, settings )
63+
}
5464
}
5565
} )
5666
}

src/util/blocks.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,14 +489,6 @@ export const addStackableBlockCategory = () => {
489489
* @param {Object} _settings The block properties to register
490490
*/
491491
export const registerBlockType = ( name, _settings ) => {
492-
// Do not register the block if the block is disabled.
493-
if ( ( _settings[ 'stk-block-dependency' ] in stackableSettings.stackable_block_states &&
494-
stackableSettings.stackable_block_states[ _settings[ 'stk-block-dependency' ] ] === BLOCK_STATE.DISABLED ) ||
495-
stackableSettings.stackable_block_states[ name ] === BLOCK_STATE.DISABLED
496-
) {
497-
return
498-
}
499-
500492
let settings = applyFilters( `stackable.block.metadata`, _settings || {} )
501493

502494
// If there is no variation title, then some labels in the editor will show

0 commit comments

Comments
 (0)