Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background images: remove required "file" prop #61387

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe( 'getGlobalStylesChanges and utils', () => {
background: {
backgroundImage: {
url: 'https://example.com/image.jpg',
source: 'file',
},
backgroundSize: 'contain',
backgroundPosition: '30% 30%',
Expand Down Expand Up @@ -96,7 +95,6 @@ describe( 'getGlobalStylesChanges and utils', () => {
background: {
backgroundImage: {
url: 'https://example.com/image_new.jpg',
source: 'file',
},
backgroundSize: 'contain',
backgroundPosition: '40% 77%',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 1 addition & 5 deletions packages/style-engine/src/styles/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/style-engine/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ describe( 'getCSSRules', () => {
{
background: {
backgroundImage: {
source: 'file',
url: 'https://example.com/image.jpg',
},
backgroundPosition: '50% 50%',
Expand Down
3 changes: 1 addition & 2 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4812,8 +4812,7 @@ public function test_get_top_level_background_image_styles() {
'core/paragraph' => array(
'background' => array(
'backgroundImage' => array(
'url' => 'http://example.org/image.png',
'source' => 'file',
'url' => 'http://example.org/image.png',
),
'backgroundSize' => 'cover',
'backgroundRepeat' => 'no-repeat',
Expand Down
6 changes: 0 additions & 6 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading