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

Fix duotone on parallax/repeated featured image cover blocks #65929

Merged
merged 8 commits into from
Oct 15, 2024

Conversation

ajlende
Copy link
Contributor

@ajlende ajlende commented Oct 7, 2024

What?

Updates the cover block to render a <div> background when using featured images.

The best way to review this is to compare with the cover block's save function as the newly added code should mirror that when a featured image is used.

Why?

Fixes #50828

Cover blocks using featured images didn't pick up duotone because they weren't using an element for the featured image.

How?

Generate a <div> instead of setting background-image for cover blocks using featured images.

Testing Instructions

<!-- wp:query {"queryId":9,"query":{"perPage":12,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"taxQuery":null,"parents":[],"format":[]}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:cover {"useFeaturedImage":true,"hasParallax":true,"dimRatio":0,"isUserOverlayColor":true,"isDark":false,"style":{"color":{"duotone":"var:preset|duotone|grayscale"}}} -->
<div class="wp-block-cover is-light has-parallax"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-0 has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size"></p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->
<!-- /wp:post-template --></div>
<!-- /wp:query -->
  1. Create some posts that have featured images.
  2. Insert above content or add the following structure.
    • Query loop block
      • Cover block
        • Enable featured image
        • Enable parallax (also try repeat)
        • Enable duotone filter
  3. Save and view the page to confirm that the featured images cover blocks show the duotone effect.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

Before

Screen Shot 2024-10-07 at 16 09 32

After

Screen Shot 2024-10-07 at 16 09 13

@ajlende ajlende added [Type] Bug An existing feature does not function as intended [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Oct 7, 2024
@ajlende ajlende self-assigned this Oct 7, 2024
@ajlende ajlende requested a review from ajitbohra as a code owner October 7, 2024 21:15
Copy link

github-actions bot commented Oct 7, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ajlende <ajlende@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: mrfoxtalbot <mrfoxtalbot@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: henriqueiamarino <iamarinoh@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

packages/block-library/src/cover/index.php Outdated Show resolved Hide resolved
packages/block-library/src/cover/index.php Outdated Show resolved Hide resolved
Comment on lines +74 to +81
/*
* Inserts the featured image between the (1st) cover 'background' `span` and 'inner_container' `div`,
* and removes eventual whitespace characters between the two (typically introduced at template level)
*/
$inner_container_start = '/<div\b[^>]+wp-block-cover__inner-container[\s|"][^>]*>/U';
if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) {
$offset = $matches[0][1];
$content = substr( $content, 0, $offset ) . $image . substr( $content, $offset );
Copy link
Contributor Author

@ajlende ajlende Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from L37-L45 above as both branches of the conditional need to insert content in the same place.

Copy link
Contributor

@jeryj jeryj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on a pairing call. Tested with various combinations of the cover block and confirmed this fixes the issue and aligns editor and frontend HTML output.

@ajlende ajlende merged commit 7590b3d into trunk Oct 15, 2024
63 checks passed
@ajlende ajlende deleted the fix/duotone-cover-featured-image branch October 15, 2024 14:23
@ajlende ajlende added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 15, 2024
@github-actions github-actions bot added this to the Gutenberg 19.5 milestone Oct 15, 2024
@github-actions github-actions bot removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 15, 2024
gutenbergplugin pushed a commit that referenced this pull request Oct 15, 2024
Co-authored-by: ajlende <ajlende@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: mrfoxtalbot <mrfoxtalbot@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: henriqueiamarino <iamarinoh@git.wordpress.org>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Oct 15, 2024
Copy link

I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 1774792

karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
…ss#65929)

Co-authored-by: ajlende <ajlende@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: mrfoxtalbot <mrfoxtalbot@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: henriqueiamarino <iamarinoh@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Cover Affects the Cover Block - used to display content laid over a background image [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duotone filter not showing on Covers inside Query Loops
2 participants