Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move attribute registration to function called in widget initialization
  • Loading branch information
stacimc committed Feb 1, 2022
commit 40887164f50750d5a889c6ed8db5c8fc29ddc223
3 changes: 3 additions & 0 deletions packages/customize-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import {
registerInternalWidgetIds,
registerLegacyWidgetBlock,
registerLegacyWidgetVariations,
registerWidgetGroupBlock,
Expand Down Expand Up @@ -59,6 +60,8 @@ export function initialize( editorName, blockEditorSettings ) {
block.name.startsWith( 'core/navigation' )
);
} );

registerInternalWidgetIds();
registerCoreBlocks( coreBlocks );
registerLegacyWidgetBlock();
if ( process.env.IS_GUTENBERG_PLUGIN ) {
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@wordpress/block-library';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
import {
registerInternalWidgetIds,
registerLegacyWidgetBlock,
registerLegacyWidgetVariations,
registerWidgetGroupBlock,
Expand Down Expand Up @@ -85,7 +86,10 @@ export function initialize( id, settings ) {
themeStyles: true,
} );

registerInternalWidgetIds();

dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();

registerCoreBlocks( coreBlocks );
registerLegacyWidgetBlock();
if ( process.env.IS_GUTENBERG_PLUGIN ) {
Expand Down
23 changes: 15 additions & 8 deletions packages/widgets/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export function getWidgetIdFromBlock( block ) {
* @return {Block} The updated block.
*/
export function addWidgetIdToBlock( block, widgetId ) {
block.attributes.__internalWidgetId = widgetId;
return block;
return {
...block,
attributes: {
...( block.attributes || {} ),
__internalWidgetId: widgetId,
},
};
}

/**
Expand All @@ -39,7 +44,7 @@ export function addWidgetIdToBlock( block, widgetId ) {
*
* @return {Object} Updated block settings.
*/
function addAttributes( settings ) {
function addInternalWidgetIdAttribute( settings ) {
return {
...settings,
attributes: {
Expand All @@ -52,8 +57,10 @@ function addAttributes( settings ) {
};
}

addFilter(
'blocks.registerBlockType',
'core/widget/addAttributes',
addAttributes
);
export function registerInternalWidgetIds() {
addFilter(
'blocks.registerBlockType',
'core/widget/addAttributes',
addInternalWidgetIdAttribute
);
}