From 85572b7c61eed611b10292be7a0216e35b90d6af Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 6 May 2024 15:03:39 +1000 Subject: [PATCH 1/2] Remove file prop from background block supports, and always default to file --- lib/block-supports/background.php | 4 ++-- .../global-styles/test/get-global-styles-changes.js | 2 -- packages/block-editor/src/hooks/background.js | 2 +- packages/style-engine/src/styles/background/index.ts | 6 +----- packages/style-engine/src/test/index.js | 1 - phpunit/class-wp-theme-json-test.php | 1 - schemas/json/theme.json | 6 ------ 7 files changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/block-supports/background.php b/lib/block-supports/background.php index 7095789722959..8e3c06159a120 100644 --- a/lib/block-supports/background.php +++ b/lib/block-supports/background.php @@ -53,10 +53,10 @@ function gutenberg_render_background_support( $block_content, $block ) { } $background_styles = array(); - $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover'; $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array(); - if ( isset( $background_styles['backgroundImage']['source'] ) && 'file' === $background_styles['backgroundImage']['source'] && isset( $background_styles['backgroundImage']['url'] ) ) { + if ( ! empty( $background_styles['backgroundImage'] ) ) { + $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover'; $background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null; $background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null; diff --git a/packages/block-editor/src/components/global-styles/test/get-global-styles-changes.js b/packages/block-editor/src/components/global-styles/test/get-global-styles-changes.js index 6eb4974ec041a..9c220da7ead12 100644 --- a/packages/block-editor/src/components/global-styles/test/get-global-styles-changes.js +++ b/packages/block-editor/src/components/global-styles/test/get-global-styles-changes.js @@ -20,7 +20,6 @@ describe( 'getGlobalStylesChanges and utils', () => { background: { backgroundImage: { url: 'https://example.com/image.jpg', - source: 'file', }, backgroundSize: 'contain', backgroundPosition: '30% 30%', @@ -96,7 +95,6 @@ describe( 'getGlobalStylesChanges and utils', () => { background: { backgroundImage: { url: 'https://example.com/image_new.jpg', - source: 'file', }, backgroundSize: 'contain', backgroundPosition: '40% 77%', diff --git a/packages/block-editor/src/hooks/background.js b/packages/block-editor/src/hooks/background.js index 3d47f42645afc..3e23efcbf5fc9 100644 --- a/packages/block-editor/src/hooks/background.js +++ b/packages/block-editor/src/hooks/background.js @@ -59,7 +59,7 @@ export function setBackgroundStyleDefaults( backgroundStyle ) { let backgroundStylesWithDefaults; // Set block background defaults. - if ( backgroundImage?.source === 'file' && !! backgroundImage?.url ) { + if ( !! backgroundImage?.url ) { if ( ! backgroundStyle?.backgroundSize ) { backgroundStylesWithDefaults = { backgroundSize: 'cover', diff --git a/packages/style-engine/src/styles/background/index.ts b/packages/style-engine/src/styles/background/index.ts index 748cb15b4f309..a8c8679888e15 100644 --- a/packages/style-engine/src/styles/background/index.ts +++ b/packages/style-engine/src/styles/background/index.ts @@ -8,11 +8,7 @@ const backgroundImage = { name: 'backgroundImage', generate: ( style: Style, options: StyleOptions ) => { const _backgroundImage = style?.background?.backgroundImage; - if ( - typeof _backgroundImage === 'object' && - _backgroundImage?.source === 'file' && - _backgroundImage?.url - ) { + if ( typeof _backgroundImage === 'object' && _backgroundImage?.url ) { return [ { selector: options.selector, diff --git a/packages/style-engine/src/test/index.js b/packages/style-engine/src/test/index.js index 5869c4a349baa..fbccc8c48bc92 100644 --- a/packages/style-engine/src/test/index.js +++ b/packages/style-engine/src/test/index.js @@ -226,7 +226,6 @@ describe( 'getCSSRules', () => { { background: { backgroundImage: { - source: 'file', url: 'https://example.com/image.jpg', }, backgroundPosition: '50% 50%', diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 8df33334e82d0..4cca23062b312 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -4813,7 +4813,6 @@ public function test_get_top_level_background_image_styles() { 'background' => array( 'backgroundImage' => array( 'url' => 'http://example.org/image.png', - 'source' => 'file', ), 'backgroundSize' => 'cover', 'backgroundRepeat' => 'no-repeat', diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 755fb09e57e3c..773419d472f33 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -2331,12 +2331,6 @@ { "type": "object", "properties": { - "source": { - "description": "The origin of the image. 'file' denotes that the 'url' is a path to an image or other file.", - "type": "string", - "enum": [ "file" ], - "default": "file" - }, "url": { "description": "A URL to an image file.", "type": "string" From ef1427d7584095002f530ce949903bb0e7bb0dce Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 6 May 2024 15:16:34 +1000 Subject: [PATCH 2/2] Lint --- phpunit/class-wp-theme-json-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 4cca23062b312..00799b7ba0b47 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -4812,7 +4812,7 @@ public function test_get_top_level_background_image_styles() { 'core/paragraph' => array( 'background' => array( 'backgroundImage' => array( - 'url' => 'http://example.org/image.png', + 'url' => 'http://example.org/image.png', ), 'backgroundSize' => 'cover', 'backgroundRepeat' => 'no-repeat',