Skip to content

Commit d040811

Browse files
committed
Pass resolved URIs to display inherited background image styles with relative paths
Also, output any background styles, even if there's no background image
1 parent 47a389a commit d040811

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/block-supports/background.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ function gutenberg_render_background_support( $block_content, $block ) {
5252
return $block_content;
5353
}
5454

55-
$background_styles = array();
56-
$background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array();
55+
$background_styles = array();
56+
$background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null;
57+
$background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null;
58+
$background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null;
59+
$background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null;
5760

5861
if ( ! empty( $background_styles['backgroundImage'] ) ) {
59-
$background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover';
60-
$background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null;
61-
$background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null;
62-
62+
$background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover';
6363
// If the background size is set to `contain` and no position is set, set the position to `center`.
6464
if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) {
6565
$background_styles['backgroundPosition'] = 'center';

packages/block-editor/src/components/global-styles/background-panel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function BackgroundImageControls( {
269269
inheritedValue,
270270
onRemoveImage = noop,
271271
displayInPanel,
272+
themeFileURIs,
272273
} ) {
273274
const mediaUpload = useSelect(
274275
( select ) => select( blockEditorStore ).getSettings().mediaUpload,
@@ -392,7 +393,10 @@ function BackgroundImageControls( {
392393
name={
393394
<InspectorImagePreviewItem
394395
className="block-editor-global-styles-background-panel__image-preview"
395-
imgUrl={ url }
396+
imgUrl={ getResolvedThemeFilePath(
397+
url,
398+
themeFileURIs
399+
) }
396400
filename={ title }
397401
label={ imgLabel }
398402
/>
@@ -706,6 +710,7 @@ export default function BackgroundPanel( {
706710
onChange={ onChange }
707711
style={ value }
708712
inheritedValue={ inheritedValue }
713+
themeFileURIs={ themeFileURIs }
709714
displayInPanel
710715
onRemoveImage={ () => {
711716
setIsDropDownOpen( false );
@@ -727,6 +732,7 @@ export default function BackgroundPanel( {
727732
onChange={ onChange }
728733
style={ value }
729734
inheritedValue={ inheritedValue }
735+
themeFileURIs={ themeFileURIs }
730736
/>
731737
) }
732738
</div>

0 commit comments

Comments
 (0)