Skip to content

Commit

Permalink
Premium Content Block: Update Transformation Rules (#38569)
Browse files Browse the repository at this point in the history
  • Loading branch information
lezama authored Jul 28, 2024
1 parent fa559b8 commit c4d288d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit c4d288d

Please sign in to comment.