Skip to content

Commit

Permalink
clone blocks on insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 2, 2021
1 parent 241908f commit d397918
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/block-library/src/query/edit/query-block-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import { useDispatch } from '@wordpress/data';
import { __, _x } from '@wordpress/i18n';
import { SelectControl, ToggleControl } from '@wordpress/components';
import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks';
import {
cloneBlock,
createBlocksFromInnerBlocksTemplate,
} from '@wordpress/blocks';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -40,13 +43,15 @@ const QueryBlockSetup = ( {
);
}
};
const onBlockPatternSelect = ( queryBlock ) => {
const onBlockPatternSelect = ( blocks ) => {
const clonedBlocks = blocks.map( ( block ) => cloneBlock( block ) );
// We need to override the attributes that can be set in the Placeholder.
Object.assign( queryBlock[ 0 ].attributes.query, {
Object.assign( clonedBlocks[ 0 ].attributes.query, {
inherit: query.inherit,
postType: query.postType,
perPage: null,
} );
replaceBlocks( clientId, queryBlock );
replaceBlocks( clientId, clonedBlocks );
};
const inheritToggleHelp = !! inherit
? _x(
Expand Down

0 comments on commit d397918

Please sign in to comment.