From de6c04bc15da6d2bc37669111819f10293b9d70c Mon Sep 17 00:00:00 2001 From: iseulde Date: Mon, 9 Apr 2018 21:36:30 +0200 Subject: [PATCH] Preserve citation when unwrapping the blocks --- blocks/library/pullquote/index.js | 12 ++++++++++++ .../components/block-settings-menu/block-unwrap.js | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/blocks/library/pullquote/index.js b/blocks/library/pullquote/index.js index 324c2acadd321e..d94d0701de6921 100644 --- a/blocks/library/pullquote/index.js +++ b/blocks/library/pullquote/index.js @@ -46,6 +46,18 @@ export const settings = { attributes: blockAttributes, + transforms: { + to: [ + { + type: 'unwrap', + transform: ( { citation }, innerBlocks ) => [ + ...innerBlocks, + createBlock( 'core/paragraph', { content: citation } ), + ], + }, + ], + }, + getEditWrapperProps( attributes ) { const { align } = attributes; if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) { diff --git a/editor/components/block-settings-menu/block-unwrap.js b/editor/components/block-settings-menu/block-unwrap.js index f936b22635e224..72d558c55b37c5 100644 --- a/editor/components/block-settings-menu/block-unwrap.js +++ b/editor/components/block-settings-menu/block-unwrap.js @@ -2,7 +2,7 @@ * External dependencies */ import { connect } from 'react-redux'; -import { noop, flatMap } from 'lodash'; +import { noop, flatMap, find } from 'lodash'; /** * WordPress dependencies @@ -10,6 +10,7 @@ import { noop, flatMap } from 'lodash'; import { __ } from '@wordpress/i18n'; import { IconButton, withContext } from '@wordpress/components'; import { compose } from '@wordpress/element'; +import { getBlockTransforms } from '@wordpress/blocks'; /** * Internal dependencies @@ -50,7 +51,10 @@ export default compose( onUnwrap( blocks ) { dispatch( replaceBlocks( ownProps.uids, - flatMap( blocks, ( { innerBlocks } ) => innerBlocks ), + flatMap( blocks, ( { name, attributes, innerBlocks } ) => { + const transform = find( getBlockTransforms( 'to', name ), { type: 'unwrap' } ); + return transform ? transform.transform( attributes, innerBlocks ) : innerBlocks; + } ), ) ); }, } )