-
Couldn't load subscription status.
- Fork 4.6k
Image block: Save <figcaption> if caption attr is bound
#71483
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
Image block: Save <figcaption> if caption attr is bound
#71483
Conversation
|
Size Change: +75 B (0%) Total Size: 1.94 MB
ℹ️ View Unchanged
|
|
Do you have any reasons why complex alternatives should be even considered in contrast to this proposal? |
Right now I find the "simple" solution (this PR) quite compelling, as it doesn't require new directives, block deprecations, etc. It does however depend on this assumption:
The latter is implemented by WordPress/wordpress-develop#9702. (I have yet to backport this to GB; I've started work on backporting the underlying Core changeset here). As for potential advantages of the more complex solutions: It could be argued that solutions like the We have full control over which block attributes are supported by Block Bindings, so we could try to go ahead with this PR and see which of the attributes that conditionally add HTML elements we can cover with it (e.g. Pullquote's |
|
Thank you for sharing the additional context. It feels like focusing on this PR and addressing all the points from #71483 (comment) is the most straightforward way to go without going into complex backward compatibility challenges. |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Yes, let's include it. One remark, I would put the filter inside the Gutenberg compat layer, rather than next to the code that gets synced to WordPress core. |
3d24e43 to
077c0f4
Compare
|
Flaky tests detected in 3b103b2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17776642404
|
Good point. Done in 4d94de2. I'll file a PR to do the same to move this filter out of the Date block's code. |
|
Is it ready for the final round of testing? Any leads on what wasn't working for me that I noted in #71483 (comment)? |
b4a27f5 to
53d072e
Compare
|
Thank you! I'd like to merge #71691 before this, since otherwise, this PR has the potential to actually break Pattern Overrides in the edge case that you found. I'll keep it set to "Blocked" for now. |
3dbc15d to
3b103b2
Compare
|
@ockham is there a reason we need to limit this to the image block, or would this work generally for all blocks as part of passing data into We could save some zero-width space, or an internal Unicode code point, or a zero, or whatever is appropriate for the type of the attribute, and clear it out after |
I think it's going to be our strategy for all blocks that have attributes that we want to support Block Bindings, and whose presence determines whether or not certain elements are included in the markup. (Another example would be the Pullquote block's AFAICS, this will always require some logic in the individual block's
Based on the points you raised on this ticket, and on some further discussion with @gziolo and @cbravobernal, our current thinking is to conditionally remove empty elements in the block's IIUC, the placeholder characters you're suggesting would unlock a more generic way of removing "unneeded"/empty HTML elements. They do seem to come with some drawbacks; for example, as you hinted at, we might need to make them compatible with different attribute types. Do you think they're overall preferential over "making it the individual block's problem"? |
I still believe that it will be simpler and more reliable and easier for developers to simply duplicate their block rendering code in PHP than constructing all of these systems. However, I hadn’t considered previously that we might have ways to automate this a bit in a more reliable way. Actually this is more akin to the approach Bits would provide were they were. The Bit itself is content inside an attribute so the situation kind of takes care of itself. Basically, I think it’s reasonable to assume that the presence of a binding suggests non-empty data. This is definitely not always the case, but usually will be. A post’s author or item’s price will likely be there, otherwise we wouldn’t add them as a binding. Conditional logic has to be handled in any system using it. On the other hand, the placeholder is a blurry way of saying, “just store a Bit”. By passing bindings into attribute on the way into the |
Correct me if I'm wrong. Do you propose we start working on bits, and use them too as placeholders for bindings? That way, the bit is added on the How do you imagine adding a figcaption? Can you provide an example? |
Well I do think that Bits is still good to work on, but a different problem than this one, as Bits still don’t answer the question of what to do when markup is conditional, or computed based on the value of the Bit.
If we do store the Bit as the placeholder then we don’t have to do anything on the Gutenberg side — the Image block will save a
The main thrust of what I was getting at with the quote you provided is that I think building a generalized system to handle conditional rendering is going to be a deadend and we’ll hit it fast. My proposal is that if someone wants to add or remove Whether by block Bindings or by Bits, these realized values can be passed into the render callback and the block rendering code need not be aware of the fact that an attribute’s value is pulled from a binding vs. having been written statically. All it knows is that there is HTML already there and there are concrete attribute values. |
| @@ -0,0 +1,3 @@ | |||
| https://github.com/WordPress/wordpress-develop/pull/9702 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've closed WordPress/wordpress-develop#9702 in favor of WordPress/wordpress-develop#9949.
I've filed a GB PR to update this backport changelog: #71849.





What?
Alternative to #70642 and #71462.
Companion to WordPress/wordpress-develop#9702.
When saving the Image Block, include the
<figcaption>element:captionattribute is set, orNote that this PR should only be merged once WordPress/wordpress-develop#9702 has been merged to Core, and backported to GB, since this PR will otherwise lead to empty
<figcaption>s being rendered on the frontend.Why?
To allow Block Bindings to bind the
captionattribute to a Block Bindings source. If the<figcaption>element remains empty -- even after binding -- it will be removed at render time (although probably not by the code in this PR, but by WordPress/wordpress-develop#9702).How?
See "What?". Additionally, the caption control is now enabled in the block toolbar if the block is part of a pattern.
Code is largely
stolen frominspired by #70642.Testing Instructions
The following instructions describe using "normal" Block Bindings for testing this PR. Alternatively, you can use Pattern Overrides to test it; @cbravobernal will know how to do that 😬
captionattribute to a Block Bindings source.<figcaption>element.