Block Bindings: Add support for Cover block id and url attrs#74610
Block Bindings: Add support for Cover block id and url attrs#74610
Conversation
|
Size Change: +5 B (0%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
db4d151 to
634d383
Compare
045c9d4 to
7b4b270
Compare
a60a6fe to
62bd8c8
Compare
90cd448 to
94ea72b
Compare
94ea72b to
eccc448
Compare
|
Flaky tests detected in f0ad9db. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22628077846
|
|
We should be able to use |
c416625 to
654dde7
Compare
654dde7 to
960619d
Compare
|
PHP Unit tests are failing reproducibly on this PR (but not elsewhere). I can't however see at a glance how the failure is related to the code changes in this PR: Expected vs actual: - grid-template-columns:repeat(auto-fill, minmax(max(min(12rem, 100%), (100% - (99px * (3 - 1))) /3), 1fr))
+ grid-template-columns:repeat(auto-fill, minmax(max(min(12rem, 100%), (100% - (24px * (3 - 1))) /3), 1fr)) |
See #74610 (comment). Fixed in 1dd5e37. |
There was a problem hiding this comment.
Changes to this file might require a backport to Core.
d7bf15a to
f4b1608
Compare
| // User can change the featured image outside of the block, but we still | ||
| // need to update the block when that happens. This effect should only | ||
| // run when the featured image changes in that case. All other cases are | ||
| // handled in their respective callbacks. |
There was a problem hiding this comment.
Need to update this comment to reflect that it also covers the case where the image is set via Block Bindings.
f4b1608 to
f0ad9db
Compare
|
Quick update, the main blocker for this feature is now the missing parallax support. From the PR description:
We hope to land a baseline implementation of a CSS Processor during the WP 7.1 cycle, which will then unblock this PR. |
There was a problem hiding this comment.
Need to move this to backport-changelog/7.1/
What?
Add Block Bindings support for the Cover block's
idandurlattributes. See #74109 (comment) for context.Why?
The Cover block is one of the more prominent blocks; adding support for Block Bindings will also unlock Pattern Overrides support for it.
Additionally, the Cover block presents a few problems which, when solved, can also inform the changes needed for other blocks to add support for Block Bindings.
How?
On the client side, the architecture of the Cover block's Edit component is such that it updates a number of its computed attributes (
dimRatioetc.) in response to event handlers on specific block controls, e.g. when manually setting a new background image. This doesn't work for Block Bindings, where the attribute is connected to a Block Bindings source through a mechanism that's outside of the block's control.Instead, this PR adds logic to update those attributes via the block Edit component's
useEffect()-- which was previously only used to react to an updated featured image (as that is typically also updated "outside" of the block itself). More background and discussion on this are available here and here.On the server side, we add some processing of block attributes within the block markup (via the HTML API), similar to what we already had in place for sourced attributes. The difference here is that the Cover block's
idandurlattributes aren't actually sourced attributes, but require similar treatment. To this end, theblock_bindings_attribute_replaced_in_markupfilter is introduced.Testing Instructions
Use this with #75625 (which adds a
featured_media.idand afeatured_media.urlfield to thecore/post-datasource).idandurlattributes to thecore/post-datasource'sfeatured_image.idandfeatured_image.urlfields.core/post-datasource'sfeatured_image.*fields. Verify that it correctly updates the image it shows.TODO
dimRatioattribute default value of100(=fully opaque). This results in an opaque black overlay that hides the entire image.urlis bound (butidisn't), meaning that the bound image could possibly be external (which isn't currently supported by the Cover block).urlattribute is bound, theidattribute also requires binding to the same source (unless we can find a way where that's not needed).background-imageinside astyleattribute, rather than an<img src="...">attribute=. AFAIK, the HTML API cannot yet safely modifystyleattributes (as that's CSS).WordPress/php-toolkit, but we'd need to copy quite a bit of code over in order to get that to work.Follow-up
featuredMediainformation fromcore/post-datasource #75625. This will allow connecting a Cover block's attribute to the current post's featured image in a Block Bindings-native way (and will permit us to remove the custom code from the Cover block that's currently covering this use case).core/post-datareturn a compositefeatured_mediafield (which is itself an object withidandurlkeys)? Is there precedent for a media type in the Fields API?useEffectEventonce it becomes available (see Block Bindings: Add support for Cover block id and url attrs #74610 (comment)).