diff --git a/packages/block-library/src/buttons/index.js b/packages/block-library/src/buttons/index.js index 211c07f4e43ad0..4777968dd1e710 100644 --- a/packages/block-library/src/buttons/index.js +++ b/packages/block-library/src/buttons/index.js @@ -7,6 +7,7 @@ import { button as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import transforms from './transforms'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -26,6 +27,7 @@ export const settings = { align: true, alignWide: false, }, + transforms, edit, save, }; diff --git a/packages/block-library/src/buttons/transforms.js b/packages/block-library/src/buttons/transforms.js new file mode 100644 index 00000000000000..a558b580741d34 --- /dev/null +++ b/packages/block-library/src/buttons/transforms.js @@ -0,0 +1,32 @@ +/** + * WordPress dependencies + */ +import { createBlock } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import { name } from './block.json'; + +const transforms = { + from: [ + { + type: 'block', + isMultiBlock: true, + blocks: [ 'core/button' ], + transform: ( buttons ) => + // Creates the buttons block + createBlock( + name, + {}, + // Loop the selected buttons + buttons.map( ( attributes ) => + // Create singular button in the buttons block + createBlock( 'core/button', attributes ) + ) + ), + }, + ], +}; + +export default transforms;