From c4d288dae84d157974f4b70c7584bf038c932e44 Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Sun, 28 Jul 2024 18:40:27 -0300 Subject: [PATCH] Premium Content Block: Update Transformation Rules (#38569) --- .../update-premium-content-block-transform | 4 +++ .../blocks/premium-content/editor.js | 35 +++++++------------ 2 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-premium-content-block-transform diff --git a/projects/plugins/jetpack/changelog/update-premium-content-block-transform b/projects/plugins/jetpack/changelog/update-premium-content-block-transform new file mode 100644 index 0000000000000..47d814b544824 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-premium-content-block-transform @@ -0,0 +1,4 @@ +Significance: major +Type: enhancement + +Premium Content Block: Only show it as a transformation option if group or columns blocks are selected or if multiple blocks are selected. diff --git a/projects/plugins/jetpack/extensions/blocks/premium-content/editor.js b/projects/plugins/jetpack/extensions/blocks/premium-content/editor.js index 712f5ec86552c..9b1de393d9dbd 100644 --- a/projects/plugins/jetpack/extensions/blocks/premium-content/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/premium-content/editor.js @@ -23,18 +23,6 @@ import { settings as subscriberViewBlockSettings, } from './subscriber-view/.'; -/** - * A list of blocks that should be disallowed to be transformed to Premium content block since they are mostly markup blocks. - */ -const disallowFromTransformations = [ - 'core/nextpage', - 'core/spacer', - 'core/separator', - 'core/more', - 'core/loginout', - 'core/post-navigation-link', -]; - /** * Check if the given blocks are transformable to premium-content block * @@ -47,6 +35,16 @@ const disallowFromTransformations = [ * @returns {boolean} Whether the blocks should be allowed to be transformed to a premium content block */ const blocksCanBeTransformed = blocks => { + if ( ! blocks ) { + return false; + } + + if ( blocks.length === 1 ) { + if ( ! [ 'core/group', 'core/columns' ].includes( blocks[ 0 ].name ) ) { + return false; + } + } + // Avoid transforming any premium-content block. if ( blocks.some( blockContainsPremiumBlock ) ) { return false; @@ -58,13 +56,7 @@ const blocksCanBeTransformed = blocks => { return false; } - // Check if the blocks selected are all in the disallowFromTransformations. - // If they are, they don't have any value in allowing them to be transformed to Premium Content. - const isInDisallowList = blocks.every( block => - disallowFromTransformations.includes( block.name ) - ); - - return ! isInDisallowList; + return true; }; registerJetpackBlockFromMetadata( @@ -82,9 +74,8 @@ registerJetpackBlockFromMetadata( if ( fromAttributes.some( attributes => attributes.isPremiumContentChild ) ) { return false; } - // The fromBlocks parameter doesn't exist in Gutenberg < 11.1.0, so if it isn't passed, allow the - // match, fallback code in the convert method will handle it. - return fromBlocks === undefined || blocksCanBeTransformed( fromBlocks ); + + return blocksCanBeTransformed( fromBlocks ); }, __experimentalConvert( blocks ) { // This is checked here as well as in isMatch because the isMatch function isn't fully compatible