Skip to content

Commit

Permalink
Add transform from old gallery to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Davies committed Mar 4, 2021
1 parent 448d2b8 commit b9ae71a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/block-library/src/gallery/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,46 @@ const transforms = {
return block;
},
},
{
// Allow transform to new gallery format if experimental flag enabled.
type: 'block',
isMultiBlock: false,
blocks: [ 'core/gallery' ],
priority: 1,
isMatch( { ids } ) {
const settings = select( blockEditorStore ).getSettings();
return settings.__experimentalGalleryRefactor && ids.length > 0;
},
transform( { images, linkTo, sizeSlug } ) {
let link;
switch ( linkTo ) {
case 'post':
link = LINK_DESTINATION_ATTACHMENT;
break;
case 'file':
link = LINK_DESTINATION_MEDIA;
break;
default:
link = LINK_DESTINATION_NONE;
break;
}
const innerBlocks = images.map( ( image ) =>
createBlock( 'core/image', {
id: parseInt( image.id, 10 ),
url: image.url,
alt: image.alt,
caption: image.caption,
linkDestination: link,
} )
);

return createBlock(
'core/gallery',
{ sizeSlug, linkTo: link },
innerBlocks
);
},
},
],
to: [
{
Expand Down

0 comments on commit b9ae71a

Please sign in to comment.