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

Backport aspect ratio block support #5963

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Jan 29, 2024

Backport the aspect ratio block support feature from the Gutenberg plugin, that originally landed in: WordPress/gutenberg#56897 and WordPress/gutenberg#58414

Note this PR backports the PHP parts of the block support. This can be safely done prior to the JS packages landing for core, as the UI for the feature will not be exposed until the JS packages are updated.

  • In a post or page add the following markup that contains a Cover block with an aspect-ratio set:
<!-- wp:cover {"customOverlayColor":"#bd6c6c","isUserOverlayColor":true,"isDark":false,"style":{"dimensions":{"aspectRatio":"16/9"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-100 has-background-dim" style="background-color:#bd6c6c"></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">A cover block in 16:9</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->
  • Note: at this stage you won't yet see the aspect ratio rendered in the editor — this is to be expected as JS rendering will only happen once the JS packages are updated.
  • Save the post or page and load the post on the site frontend. You should see that the aspect ratio rules are output for this block, along with a min-height:unset rule:
image

Trac ticket: https://core.trac.wordpress.org/ticket/60365


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@andrewserong andrewserong force-pushed the backport/aspect-ratio-block-support branch from c7addf5 to 2b6495e Compare January 29, 2024 22:52
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Couple of minor questions below but overall LGTM!

'value' => 'unset',
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth adding an @since for this change in compute_style_properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Added in: 03d2d01

public function data_dimensions_block_support() {
return array(
'aspect ratio style is applied, with min-height unset' => array(
'theme_name' => 'block-theme-child-with-fluid-typography',
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for using this particular theme as opposed to, say, block-theme-child?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, block-theme-child-with-fluid-typography has appearanceTools set to true so that the block support will be in use. I think we're doing the same with the background image support, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see! Might be worth consolidating some of those themes at some point but this is fine for now.

@andrewserong andrewserong force-pushed the backport/aspect-ratio-block-support branch from 03d2d01 to 4dc1c27 Compare January 31, 2024 01:57
@tellthemachines
Copy link
Contributor

Committed in r57491.

@andrewserong
Copy link
Contributor Author

Wonderful, thank you @tellthemachines! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants