Skip to content

Commit

Permalink
Cover: Merge block and global styles (#49434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Mar 30, 2023
1 parent a636abc commit 7547ad4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions packages/block-library/src/cover/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ function render_block_core_cover( $attributes, $content ) {
}
$current_featured_image = get_the_post_thumbnail_url();

$styles = 'background-image:url(' . esc_url( $current_featured_image ) . '); ';

if ( isset( $attributes['minHeight'] ) ) {
$height_unit = empty( $attributes['minHeightUnit'] ) ? 'px' : $attributes['minHeightUnit'];
$height = " min-height:{$attributes['minHeight']}{$height_unit}";

$styles .= $height;
}

$processor = new WP_HTML_Tag_Processor( $content );
$processor->next_tag();
$processor->set_attribute( 'style', $styles );

$styles = $processor->get_attribute( 'style' );
$merged_styles = ! empty( $styles ) ? $styles . ';' : '';
$merged_styles .= 'background-image:url(' . esc_url( $current_featured_image ) . ');';

$processor->set_attribute( 'style', $merged_styles );
$content = $processor->get_updated_html();
}

Expand Down
4 changes: 2 additions & 2 deletions phpunit/blocks/render-block-cover-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Tests_Blocks_Render_Cover extends WP_UnitTestCase {
/**
* Post object.
*
* @var array
* @var object
*/
protected static $post;

Expand Down Expand Up @@ -76,7 +76,7 @@ public function test_gutenberg_render_block_core_cover() {
'minHeight' => '100px',
);

$content = '<div class="wp-block-cover"><span></span><div class="wp-block-cover__inner-container"></div></div>';
$content = '<div class="wp-block-cover" style="min-height:100px"><span></span><div class="wp-block-cover__inner-container"></div></div>';
$rendered = gutenberg_render_block_core_cover( $attributes, $content );

$this->assertStringContainsString( wp_get_attachment_image_url( self::$attachment_id, 'full' ), $rendered );
Expand Down

0 comments on commit 7547ad4

Please sign in to comment.