diff --git a/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js b/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js index 1bea3740d79ee7..f2579cc69f3cc5 100644 --- a/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js +++ b/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js @@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n'; import { useState, useMemo } from '@wordpress/element'; import { useInstanceId } from '@wordpress/compose'; import { chevronRight } from '@wordpress/icons'; -import { cloneBlock, getBlockType } from '@wordpress/blocks'; +import { cloneBlock, getBlockTransforms } from '@wordpress/blocks'; import { MenuGroup, MenuItem, @@ -110,9 +110,11 @@ function PatternTransformationsMenu( { // everything else from the pattern's block. // If `retainAttributes` are not set, update the match // with all the selected block's attributes. - const blockType = getBlockType( block.name ); - const retainAttributes = - blockType.transforms?.retainAttributes; + const retainAttributes = getBlockTransforms( + 'to', + block.name + ).find( ( { type } ) => type === 'pattern' ) + ?.retainAttributes; let retainedBlockAttributes = block.attributes; if ( retainAttributes?.length ) { retainedBlockAttributes = retainAttributes.reduce( diff --git a/packages/block-library/src/heading/transforms.js b/packages/block-library/src/heading/transforms.js index ef0e1dddbce83a..17fcb2719e6055 100644 --- a/packages/block-library/src/heading/transforms.js +++ b/packages/block-library/src/heading/transforms.js @@ -10,7 +10,6 @@ import { getLevelFromHeadingNodeName } from './shared'; import { name } from './block.json'; const transforms = { - retainAttributes: [ 'content' ], from: [ { type: 'block', @@ -92,6 +91,7 @@ const transforms = { } ) ), }, + { type: 'pattern', retainAttributes: [ 'content' ] }, ], }; diff --git a/packages/block-library/src/paragraph/transforms.js b/packages/block-library/src/paragraph/transforms.js index 3ee12658bda9c4..e59b01ad14e3b9 100644 --- a/packages/block-library/src/paragraph/transforms.js +++ b/packages/block-library/src/paragraph/transforms.js @@ -9,7 +9,6 @@ import { createBlock, getBlockAttributes } from '@wordpress/blocks'; import { name } from './block.json'; const transforms = { - retainAttributes: [ 'content' ], from: [ { type: 'raw', @@ -38,6 +37,7 @@ const transforms = { }, }, ], + to: [ { type: 'pattern', retainAttributes: [ 'content' ] } ], }; export default transforms;