Block Bindings: Support Image block's caption attribute, remove <figcaption> if empty#9702
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| return true; | ||
| } | ||
|
|
||
| public function remove_node() { |
| // Find matching tag closer. | ||
| while ( $this->next_token() && $this->get_current_depth() >= $depth ) { | ||
| } |
There was a problem hiding this comment.
Do we need these condition?
There was a problem hiding this comment.
Yeah, this is needed. It's a loop that advances the internal cursor until a matching tag closer is found for the opener that we started from.
| , | ||
| '<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">test source value</a></div>', | ||
| ), | ||
| 'image block' => array( |
There was a problem hiding this comment.
Based on my testing experience described in WordPress/gutenberg#71483 (comment), we might need some coverage when replacing HTML attributes, too. In that particular case, src in the <img /> didn't get replaced for unknown reasons with the Pattern Overrides mechanism.
There was a problem hiding this comment.
I see it's covered in test_update_block_with_value_from_source_image_placeholder test:
wordpress-develop/tests/phpunit/tests/block-bindings/render.php
Lines 414 to 423 in e2560f1
That might be an issue in the Gutenberg implementation. However, adding more diverse cases here could still be beneficial.
There was a problem hiding this comment.
Based on my testing experience described in WordPress/gutenberg#71483 (comment), we might need some coverage when replacing HTML attributes, too. In that particular case,
srcin the<img />didn't get replaced for unknown reasons with the Pattern Overrides mechanism.
Test coverage for this scenario was added on the GB side as part of the fix to the bug you mentioned (src not being replaced).
The bug was specific to GB's compat layer (and can't manifest in Core in the same way), but we can carry over the test coverage to Core just for parity's sake.
|
Closing this due to reasons laid out in this comment. I'll follow-up with a trimmed-down PR that only adds support for the Image block's |
Implement "conditional" Block Bindings, using the example of the Image block's
captionattribute. The following cases need to be supported when that attribute is bound to a Block Bindings source:<figcaption>element is removed.<figcaption>element is added (with the caption set to the Block Bindings source value).save.jsto include a<figcaption>. This is implemented by Image block: Save<figcaption>ifcaptionattr is bound gutenberg#71483. If thecaptionattribute is empty after binding, the empty<figcaption>element will be removed by the logic that handles the case described by the second item in this list.The logic implemented in this PR isn't specific to the Image block; it can be extended to any block that conditionally includes an HTML element that corresponds to a
rich-textblock attribute (e.g. the Pullquote block'scitationattribute, which corresponds to a<cite>element). See here for some discussion related to this solution.See the screenshots in the "Testing Instructions" section for an illustrative example.
Testing Instructions
The first two cases from the above list are covered by unit tests.
To test manually, follow these instructions:
Create a new post, and paste the following markup:
The resulting content should look like this:
In the Visual Editor, select all three image blocks. Then, from the block toolbar, select "Create Pattern". Assign a name of your choice to the pattern (e.g. "Pokemons").
Below the three image blocks that now form a pattern, insert another instance of the "Pokemons" pattern. Then, edit the newly inserted instance as follows:
Publish the post, and verify that the result looks like this:
(Testing instructions largely copied from WordPress/gutenberg#70642.)
Supersedes ockham#5.
Trac ticket: https://core.trac.wordpress.org/ticket/63919
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.