-
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
Proper server-side APIs for block modification #6494
Comments
Related to #2751 |
I really like the idea of having a real object model of the blocks and making Blocks should be represented by the "Composite" pattern, to represent a tree that allows for easy traversal and modification, but can still be treated as a whole. So a call to the root object's I'll work on creating a first PR to show how such an object model could work. |
I finished a first implementation that basically does the following:
The object tree is built up of composite objects and leaf objects. However, it seems that the data model that Gutenberg uses does not construct a tree out of composite objects and leaf objects (which is a standard pattern for such a use case), but rather adds an Is that the finalized data model design, or is this still up for discussion? I can easily change the code to adapt to this data model instead, but I'd like to get confirmation first, as it seems this might have been a temporary work-around only. |
I implemented a concept for PHP block template partials, which are limited to updating or replacing the block string content. Having access to the block model from within a template partial would be extremely powerful for server-side block rendering. |
@schlessera That looks like a good start, and fairly close to what I had in mind. I'm less familiar with the composite/ leaf concept, so I'm not sure how well this works with the Gutenberg data structure. I can imagine a few more helper functions for inserting blocks might be useful (e.g. |
@schlessera you mentioned you had an initial implementation working? In the absence of any feedback from the Gutenberg team I wonder if a pull-request would provide something to review in order to get this discussion moving again? |
Related #11523 |
@schlessera I'd love to learn more about your implementation here. As I understand it, the serialisation of most blocks is handled on the JS side. We're considering how to manipulate How is your |
Can we get a status update? |
I don't believe development ever got underway on this, although I would still love to see it happen. If there is an equivalent issue/ PR somewhere it would be great to post a link - I may have just missed it. |
I can see various PHP functions for parsing blocks out of the post_content (
gutenberg_parse_blocks
,do_blocks
), but it appears not to be possible to modify these blocks server-side and insert an updated serialised content back into the database. There feels like a significant need for this, in order to support more complex use-cases.Use Cases
As a WordPress developer, I am often asked to migrate content out of legacy databases into WordPress. Usually, I migrate to ACF flexible-content and it is not unusual to be inserting several rows/ blocks of content. As block-based editors become more wide-spread it is likely that migrating between different block-based systems will become more common.
In Block migration on larger sites? #5615 the question of how to update the markup for a block across all posts was raised. If a server-side API was available it would be able to loop through all posts and modify all instances of a single block. This could be a one-time migration script either run on plugin activation or via WP-CLI (depending on the context of the plugin and site).
There is occasionally a need to allow post_content to be edited from the front-end by non-administrative users - For example, on certain types of membership sites. This is also supported by some form plugins. There is likely to be a desire to insert this content in a block-based fashion.
Ideal solution
I would love to see a proper object-based representation of the blocks, which would properly represent the inner-content, attributes and comments, with methods for updating and inserting blocks. It would be amazing if this object could be passed directly back to
wp_update_post
as thepost_content
arg, and serialised from there.The text was updated successfully, but these errors were encountered: