Skip to content

Commit

Permalink
Add test deprecation for Group block. Need to do Quote, Pullquote, Po…
Browse files Browse the repository at this point in the history
…st content and Verse

PHP linting
  • Loading branch information
ramonjd committed Jul 4, 2024
1 parent 0364d64 commit ad7beb0
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ function gutenberg_render_background_support( $block_content, $block ) {

// Remove any existing background color if a background image and gradient is set.
if ( ! empty( $background_gradient_styles['gradient'] ) && ! empty( $background_styles ) ) {
// This is just testing. The style engine should be smart enough to remove the classname for a preset, where
// it's used in the CSS string.
// And this is done in the site editor when editing the block.
// This is just testing. The style engine should be smart enough to remove the classname for a preset, where
// it's used in the CSS string.
// And this is done in the site editor when editing the block.
if ( ! empty( $styles['classnames'] ) && $preset_gradient_color ) {
foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) {
if ( 'has-background' !== $class_name ) {
Expand Down
133 changes: 133 additions & 0 deletions packages/block-library/src/group/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,139 @@ const migrateAttributes = ( attributes ) => {
};

const deprecated = [
// Version with preset gradient color and background image.
// If there is a background image and gradient preset, remove the gradient classname.
{
attributes: {
tagName: {
type: 'string',
default: 'div',
},
templateLock: {
type: [ 'string', 'boolean' ],
enum: [ 'all', 'insert', 'contentOnly', false ],
},
allowedBlocks: {
type: 'array',
},
},
supports: {
__experimentalOnEnter: true,
__experimentalOnMerge: true,
__experimentalSettings: true,
align: [ 'wide', 'full' ],
anchor: true,
ariaLabel: true,
html: false,
background: {
backgroundImage: true,
backgroundSize: true,
__experimentalDefaultControls: {
backgroundImage: true,
},
},
color: {
gradients: true,
heading: true,
button: true,
link: true,
__experimentalDefaultControls: {
background: true,
text: true,
},
},
spacing: {
margin: [ 'top', 'bottom' ],
padding: true,
blockGap: true,
__experimentalDefaultControls: {
padding: true,
blockGap: true,
},
},
dimensions: {
minHeight: true,
},
__experimentalBorder: {
color: true,
radius: true,
style: true,
width: true,
__experimentalDefaultControls: {
color: true,
radius: true,
style: true,
width: true,
},
},
position: {
sticky: true,
},
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
__experimentalDefaultControls: {
fontSize: true,
},
},
layout: {
allowSizingOnChildren: true,
},
interactivity: {
clientNavigation: true,
},
},
save( { attributes: { tagName: Tag } } ) {
return (
<Tag { ...useInnerBlocksProps.save( useBlockProps.save() ) } />
);
},
isEligible( { gradient, style } ) {
return (
gradient &&
( typeof style?.background?.backgroundImage === 'string' ||
typeof style?.background?.backgroundImage?.url ===
'string' )
);
},
migrate( attributes ) {
const { style = null, gradient } = attributes;

const hasBackgroundImage =
typeof style?.background?.backgroundImage === 'string' ||
typeof style?.background?.backgroundImage?.url === 'string';

if ( hasBackgroundImage && gradient ) {
let newClassName = attributes?.className;
if ( newClassName ) {
const regex = new RegExp(
`has-${ gradient }-gradient-background[\\s]?`,
'g'
);
newClassName = newClassName.replace( regex, '' ).trim();
}
return {
...attributes,
className: newClassName ? newClassName : undefined,
style: {
...style,
color: {
...style.color,
gradient: `var(--wp--preset--gradient--${ gradient })`,
},
},
gradient: null,
};
}
return attributes;
},
},
// Version with default layout.
{
attributes: {
Expand Down

0 comments on commit ad7beb0

Please sign in to comment.