Skip to content

Commit

Permalink
Background images: remove required "file" prop (#61387)
Browse files Browse the repository at this point in the history
* Remove file prop from background block supports, and always default to file

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
3 people authored May 6, 2024
1 parent 57c5b9a commit ccf9d33
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 19 deletions.
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

0 comments on commit ccf9d33

Please sign in to comment.