Skip to content

Commit

Permalink
Add Legacy widget to calendar block transform
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 20, 2020
1 parent 70f65da commit 896f61a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/block-library/src/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
*/
import metadata from './block.json';
import edit from './edit';
import transforms from './transforms';

const { name } = metadata;

Expand All @@ -24,4 +25,5 @@ export const settings = {
},
example: {},
edit,
transforms,
};
30 changes: 30 additions & 0 deletions packages/block-library/src/calendar/transforms.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 896f61a

Please sign in to comment.