diff --git a/packages/block-library/src/calendar/index.js b/packages/block-library/src/calendar/index.js index f04f16f409b98..09467f251db00 100644 --- a/packages/block-library/src/calendar/index.js +++ b/packages/block-library/src/calendar/index.js @@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n'; */ import metadata from './block.json'; import edit from './edit'; +import transforms from './transforms'; const { name } = metadata; @@ -24,4 +25,5 @@ export const settings = { }, example: {}, edit, + transforms, }; diff --git a/packages/block-library/src/calendar/transforms.js b/packages/block-library/src/calendar/transforms.js new file mode 100644 index 0000000000000..60282ee5f18d7 --- /dev/null +++ b/packages/block-library/src/calendar/transforms.js @@ -0,0 +1,30 @@ +/** + * WordPress dependencies + */ +import { createBlock } from '@wordpress/blocks'; + +const transforms = { + from: [ + { + type: 'block', + blocks: [ 'core/legacy-widget' ], + isMatch: ( { widgetClass } ) => { + return widgetClass === 'WP_Widget_Calendar'; + }, + transform: ( { instance } ) => { + const calendarBlock = createBlock( 'core/calendar' ); + if ( ! instance || ! instance.title ) { + return calendarBlock; + } + return [ + createBlock( 'core/heading', { + content: instance.title, + } ), + calendarBlock, + ]; + }, + }, + ], +}; + +export default transforms;