#60854 closed enhancement (fixed)
Block Hooks: Allow insertion as first or last child of Template Part block
Reported by: | Bernhard Reiter | Owned by: | Bernhard Reiter |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch needs-dev-note |
Focuses: | Cc: |
Description
In GB#57754, a mechanism was introduced to allow insertion of hooked blocks into the Navigation block, in particular as its first_child
or last_child
, thus fixing #59743. The latter was achieved by storing the ignoredHookedBlocks
array in the corresponding wp_navigation
post's post meta (instead of a metadata
attribute on the anchor block).
This technique could be applied to other blocks that fetch their inner blocks from a separate DB record (rather than having them stored inline); these are sometimes referred to as "controlled inner blocks".
There might not be a large number of container blocks with controlled inner blocks into which we'd want to inject hooked blocks; however, there's at least one obvious example: The Template Part block. It's currently not possible to inject a hooked block as its first or last child.
Note however that the code that inserts hooked blocks into the Navigation block's wp_navigation
post objects currently lives in Gutenberg. Consequently, it's advisable to absorb that code into Core first (i.e. to fix #60759) before tackling this issue.
Change History (14)
This ticket was mentioned in PR #6867 on WordPress/wordpress-develop by @tomjcafferkey.
6 months ago
#1
- Keywords has-patch added
@Bernhard Reiter commented on PR #6867:
6 months ago
#2
Is it possible to get away with even fewer changes (to block-template-utils.php, specifically) if we hook update_ignored_hooked_blocks_postmeta into rest_pre_insert_wp_template_part (like we already do for wp_navigation posts)?
As it stands using that filter in the templates controller only gives us the following information;
post_name
,ID
,post_status
andpost_content
so we don't know if its awp_template
orwp_template_part
since we don't have the post type there.
Is that really a problem though? Can't we implicitly assume wp_template_part
, since we'll be only hooking to rest_pre_insert_wp_template_part
(but not to rest_pre_insert_wp_template
)? 🤔
@Bernhard Reiter commented on PR #6867:
6 months ago
#3
Another thing I realized is that on a higher level, update_ignored_hooked_blocks_postmeta
only updates the ignoredHookedBlocks
metadata (as the function name states 😅 ); it doesn’t actually take care of block insertion (neither in the editor, nor on the frontend). So those parts would still be missing.
For the editor (i.e. the REST API), we might be able to use insert_hooked_blocks_into_rest_response
(once again like we do for wp_navigation
). The frontend is a bit trickier though.
@tomjcafferkey commented on PR #6867:
6 months ago
#4
So those parts would still be missing
Unless I'm misunderstanding what you're saying here. Those pieces are covered by the updates I made to _build_block_template...
functions since these functions are used both when building the template for the REST response _and_ the frontend. Are you suggesting I find a different way to insert the hooked blocks?
@Bernhard Reiter commented on PR #6867:
6 months ago
#5
So those parts would still be missing
Unless I'm misunderstanding what you're saying here. Those pieces are covered by the updates I made to
_build_block_template...
functions since these functions are used both when building the template for the REST response _and_ the frontend. Are you suggesting I find a different way to insert the hooked blocks?
No, that's fine! I guess I was hoping to unify first/last child insertion into wp_navigation
and wp_template_part
posts even more but got my wires crossed 😅
@Bernhard Reiter commented on PR #6867:
6 months ago
#6
I've just committed https://github.com/WordPress/wordpress-develop/pull/6885 to Core, so we can rebase this now. (We'll probably need to change the remaining assertions that are using get_post_meta()
to get _wp_ignored_hooked_blocks
to $post->meta_input['_wp_ignored_hooked_blocks']
, like you did in #6885.)
#8
@
5 months ago
- Owner set to Bernhard Reiter
- Resolution set to fixed
- Status changed from new to closed
In 58614:
@Bernhard Reiter commented on PR #6867:
5 months ago
#9
Committed to Core in https://core.trac.wordpress.org/changeset/58614.
@mukesh27 commented on PR #6867:
5 months ago
#10
@ockham Left two nit-pick feedback.
@Bernhard Reiter commented on PR #6867:
5 months ago
#12
@ockham Left two nit-pick feedback.
Fixed in https://core.trac.wordpress.org/changeset/58615. Thank you!
Trac ticket: https://core.trac.wordpress.org/ticket/60854