Skip to content

Commit

Permalink
Reverting source:theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Feb 28, 2024
1 parent 069762e commit 6bfcb74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
15 changes: 3 additions & 12 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,22 @@ function gutenberg_register_background_support( $block_type ) {
/**
* Given a theme.json or block background styles, returns the background styles for a block.
*
* @since 6.6.0
*
* @param array $background_styles Background style properties.
* @return array Style engine array of CSS string and style declarations.
*/
function gutenberg_get_background_support_styles( $background_styles = array() ) {
$background_image_source = isset( $background_styles['backgroundImage']['source'] ) ? $background_styles['backgroundImage']['source'] : null;
$background_styles['backgroundSize'] = ! empty( $background_styles['backgroundSize'] ) ? $background_styles['backgroundSize'] : 'cover';

/*
* @TODO document
* $background_styles['backgroundImage']['url'] and file source implies an image URL path.
*/
if ( ( 'file' === $background_image_source || 'theme' === $background_image_source ) && ! empty( $background_styles['backgroundImage']['url'] ) ) {
if ( 'file' === $background_image_source && ! empty( $background_styles['backgroundImage']['url'] ) ) {
// If the background size is set to `contain` and no position is set, set the position to `center`.
if ( 'contain' === $background_styles['backgroundSize'] && ! isset( $background_styles['backgroundPosition'] ) ) {
$background_styles['backgroundPosition'] = 'center';
}
}

/*
* "theme" source implies relative path to the theme directory
*/
if ( 'theme' === $background_image_source ) {
$background_styles['backgroundImage']['url'] = esc_url( get_theme_file_uri( $background_styles['backgroundImage']['url'] ) );
}

return gutenberg_style_engine_get_styles( array( 'background' => $background_styles ) );
}

Expand Down
10 changes: 0 additions & 10 deletions phpunit/block-supports/background-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,6 @@ public function data_get_background_support_styles() {
),
'expected_css' => "background-image:url('https://example.com/image.jpg');background-position:center;background-size:contain;",
),
'css generated with theme source' => array(
'background_style' => array(
'backgroundImage' => array(
'url' => 'assets/image/1024x768_e2e_test_image_size.jpeg',
'source' => 'theme',
),
'backgroundSize' => 'contain',
),
'expected_css' => "background-image:url('http://localhost:8889/wp-content/plugins/gutenberg/phpunit/data/themedir1/block-theme/assets/image/1024x768_e2e_test_image_size.jpeg');background-position:center;background-size:contain;",
),
);
}
}

0 comments on commit 6bfcb74

Please sign in to comment.