Post Content block: Allow Block Hooks child insertion#56972
Conversation
|
Flaky tests detected in 74439b5. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7198507644
|
|
I'll close this, as I'm fairly convinced that it isn't the right way forward -- especially when it comes to inserting a Like Button block below a Post Content block. Some of the downsides listed in the notes in the PR description are dealbreakers; it's awkward to try and "emulate" the Block Hooks mechanism like this, and doesn't scale to other blocks. Finally, on a conceptual level, it's better to insert a Like Button block This means that to solve the original problem, I'll focus on finding a solution for this issue. It's still possible that we'll need to apply a solution similar to what's been explored in this PR to some other blocks (e.g. Navigation) to make child insertion work. |
Untested; this code probably doesn't work yet.
What?
Try allowing
first_childandlast_childinsertion into the Post Content block.This is experimental; there's a pretty good chance that we'll never merge this code due to its limitations (see "Notes" section below).
Why?
It was brought up that this would be beneficial e.g. for inserting a Like Button block as the Post Content block's
last_child(rather thanafter) for consistency with the Classic Theme way of doing this (using thethe_contentfilter).How?
By manually applying the
hooked_block_typesfilter inside the Post Content block.Testing Instructions
Basically, follow Block Hooks instructions to insert a block as
core/post-content'slast_child.Notes
Note that due to the fact that we're doing this manually, this approach has a number of significant shortcomings, among them:
$contextavailable.Alternatives considered
We could run our Block Hooks logic on the
$contentreturned fromget_the_content()(in the Post Content block's render method), or even generically on all post content (in any given context; e.g. when runningdo_blocks).However, that would present a pretty big departure from how it's worked up to now (which was pretty much limited to templates, parts, and patterns). It's something to consider for WP 6.5 (since it might be possible thanks to the new mechanism we're using), but it'll require careful deliberation.