-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Legacy widget to calendar block transform
- Loading branch information
1 parent
70f65da
commit 896f61a
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |