-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Extensibility: Introduce BlockSave
which would work similar to BlockEdit
#3800
Comments
the |
I was looking to add some values into
Values that go into
|
@andreamiddleton These attributes are not saved or extracted from the innerHTML, you can achieve what you want by hooking into |
Oh, that's very cool! I was really close to that part of the code, thanks. This kinda makes the |
Getting back to it, I was forced to do it that way: let settings = wp.blocks.getBlockType('core/button')
wp.blocks.unregisterBlockType('core/button')
wp.blocks.registerBlockType('core/button', {
...oldSettings,
attributes: {
...settings.attributes,
heya: {
type: 'string',
default: '#cf2e2e',
},
},
}) The reason for that hack was this:
This in itself is not a problem. The problem arise when third-party plugins try to hook into A possible solution: Split the |
Good point @andreamiddleton I'm reopening and renaming the issue. We should try to address this issue. |
Alternatively we change blocks hooks to operate on the global hooks instance, then simply encourage plugin authors to register their hooks prior to the Related: #3493 (comment) |
Yes, I have tried that option. Of course it didn't worked out for me they way one would expect. Frankly, either one will work for me, whichever you get to decide to go with. |
It's going to be partially updated with #3827. |
Correct me if I'm wrong, but it's also impossible to hook to the |
@kmgalanakis kinda so. It works for blocks that are added after the initial load. Those that happened to be in the editor at the first time just got rendered without taking |
@andreiglingeanu I cannot get it working even for the blocks that are added after the initial load, unfortunately. Have you checked yourself with the latest master? |
@andreiglingeanu @kmgalanakis I'm working on the PR which should allow to add a filter after |
|
Confirmed, |
#4428 adds another improvement for |
Just merged #4428 which should further improve using hooks with the core block. Hopefully, it won't be necessary to unregister them to add modifications from now on. |
Sounds great! |
BlockSave
which would work similar to BlockEdit
@andreiglingeanu I renamed this issue because the original title in my opinion is no longer relevant to what is missing. Does it make sense? |
Yes, makes total sense It's interesting to me how blocks will behave once plugins that used to intercept the saving process would get disabled. Will those blocks just be marked as stale/broken? |
There is an unknown type handler set in here: gutenberg/blocks/library/index.js Line 90 in 24cfb23
It applies to both |
@aduth, did we introduce something similar with your change to how save is being processed? I think
It is a bit different than:
but this is done this way by design to provide a better automation for the saved content. Link to full docs for reference: https://github.com/WordPress/gutenberg/blob/master/docs/extensibility.md#modifying-blocks-experimental. |
Correct, I should have been more explicit with linking in #4786, but the new |
@andreiglingeanu, I think we addressed all concerns with the linked PRs. Let's close this one. If there are further issues discovered let's create separate actionable issues. Thanks for your feedback and all your help 💯 |
It's great, thank you for taking it in consideration! Will definitely try everything in practice and see how it plays out, thanks again. |
Issue Overview
This issue explores ways to give more flexibility for extending
core/*
block types.Context: https://wordpress.org/gutenberg/handbook/extensibility/
The current set of available hooks is very limited and is not enough for providing meaningful customizations.
Specifically:
getSaveContent.extraProps
provides no help here. It only gives us a way to add inline HTML attributes to the final block output.BlockSave
which would be similar toBlockEdit
hook. Ideally,BlockSave
should be called ingetSaveContent
which would properly allow us to proxy the final result through a component (via HOCs/render props) that will modify the resulting HTML.gutenberg/blocks/api/serializer.js
Lines 37 to 66 in ff9c02a
Probably more once I get more deeply into that...
Related Issues and/or PRs
#2474 #3318
I understand that giving such powerful things into the users hands is quite dangerous. The posts may break in case the third-party plugin gets disabled in many unexpected ways (a missing
BlockSave
, in that particular example, would potentially blow up theattributes
parsing withselector | src
sources).But, I really believe that there is a lot more to be done in that area that waits to be explored.
The text was updated successfully, but these errors were encountered: