Repository navigation
Open
Labels
Backwards CompatibilityIssues or PRs that impact backwards compatabilityIssues or PRs that impact backwards compatability[Feature] Block APIAPI that allows to express the block paradigm.API that allows to express the block paradigm.[Feature] Block TransformsBlock transforms from one block to anotherBlock transforms from one block to another[Feature] BlocksOverall functionality of blocksOverall functionality of blocks[Feature] ExtensibilityThe ability to extend blocks or the editing experienceThe ability to extend blocks or the editing experience[Feature] MediaAnything that impacts the experience of managing mediaAnything that impacts the experience of managing media[Type] EnhancementA suggestion for improvement.A suggestion for improvement.
Milestone
Description
A plugin can use the blocks.getSaveElement to modify the saved output of a Gutenberg core block. I started documenting this here: #8470 (review)
For instance, I may want to write a plugin which adds a data-pin-description attribute to an Image Block:
<!-- wp:image {"id":33863} -->
<figure class="wp-block-image"><img data-pin-description="My Pinterest description" src="http://tastyrecipes.test/wp-content/uploads/2018/03/food-dinner-pasta-broccoli.jpg" alt="" class="wp-image-33863" /></figure>
<!-- /wp:image -->
However, if the plugin is deactivated after the user adds a Pinterest Description to their Image Block, the Image Block, the block will enter into an invalid, crashed state.
The Classic Editor permits manipulation of any HTML5 element, in accordance to the entire spec. It would be ideal of Gutenberg permitted the same: #6878 (comment)
Metadata
Metadata
Assignees
Labels
Backwards CompatibilityIssues or PRs that impact backwards compatabilityIssues or PRs that impact backwards compatability[Feature] Block APIAPI that allows to express the block paradigm.API that allows to express the block paradigm.[Feature] Block TransformsBlock transforms from one block to anotherBlock transforms from one block to another[Feature] BlocksOverall functionality of blocksOverall functionality of blocks[Feature] ExtensibilityThe ability to extend blocks or the editing experienceThe ability to extend blocks or the editing experience[Feature] MediaAnything that impacts the experience of managing mediaAnything that impacts the experience of managing media[Type] EnhancementA suggestion for improvement.A suggestion for improvement.
Activity
danielbachhuber commentedon Oct 17, 2018
My workaround for this was to store my plugin data in post meta instead. There were a couple of notable downsides:
post_content, it won't persist as the user expects it to persist when the plugin is deactivated.On the plus side,
register_meta()worked surprisingly well in tandem to registering the Block attribute.Some partial code snippets:
chrisvanpatten commentedon Oct 17, 2018
Thanks for leaving the code sample @danielbachhuber I have a feeling this will come in handy on some client projects.
This also relates to #10444 which suggests allowing blocks to rebuild themselves automatically if they are able to do so.
danielbachhuber commentedon Oct 18, 2018
I ran into an odd edge case with how I implemented this with a second
register_meta()call.When I hit "Save draft", I'd see an "Updating failed." message:
The source of the error was
rest_meta_database_error, which I tracked down to:update_metadata()call: https://github.com/WordPress/WordPress/blob/56c162fbc9867f923862f64f1b4570d885f1ff03/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L332My amazingly hacky solution was to set a random value on both blobs each time the value for one attribute is changed:
danielbachhuber commentedon Nov 16, 2018
This ended up being a horrible workaround. I've instead gone back to directly modifying the block. Here's my full implementation:
aubirdgine commentedon Nov 17, 2018
@danielbachhuber I'm having the exact same issue with Gutenberg pulling out the data-pin-description HTML that Tasty Pins used to add in the classic editor! Except I am a total coding novice... Is it simple enough to implement the fix you have here (simple enough that I can do it through FTP or cPanel with basic copying and pasting) or am I just way too optimistic? I'd love to be able to have the data-pin-description code in my HTML still, but I'm pretty wary about actually modifying code cuz I'd prefer not to break my site!
mtias commentedon Nov 20, 2018
Let's continue to improve handling as outlined in #11440. The current state is our best tradeoff — things can be extended, but if the plugin code is missing a block might become invalid. Which is correct in the sense that the block wouldn't know how to further handle the extra attributes and code present in the block.
This is important for other editor cases, like mobile, where handling attributes might not be as straightforward as preserving a set of HTML attributes.
That said, work on allowing unknown attributes to carry on without blocking it has already begun, and we can continue refining the details of the implementation.
florianbrinkmann commentedon Feb 13, 2020
I have the same issue that @danielbachhuber described in his comment (#10204 (comment)), I get a
rest_meta_database_errorerror after trying to update a post which updates multiple meta values. Changing the problematic field lets me save the post, but that is a not so great workaroud.Is that something that can/should be fixed in Gutenberg?
vreemt commentedon Jan 20, 2023
related #28923
carstingaxion commentedon Jul 21, 2024
I just stumbled upon
rest_meta_database_errorwith the same situation like described by @danielbachhuber & @florianbrinkmann , while working with the Block Bindings API. Having this bug while only using core-functions surprised me a little, as I would have thought, someone else might have mentioned this before.This 3 year old ticket seems related: - #53942 (Non-single post meta multiple value update breaks post save through REST API) – WordPress Trac