mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Block Hooks: Extract insert_hooked_blocks()
function
#5609
Closed
ockham
wants to merge
5
commits into
WordPress:trunk
from
ockham:update/extract-insert-hooked-blocks
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b68aeac
Block Hooks: Extract insert_hooked_blocks() function
ockham a258a01
Remove obsolete block argument
ockham 09bff63
Change argument order
ockham 19ff5d5
Add PHPDoc
ockham 0b0f7cb
Add basic test coverage for insert_hooked_blocks
ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might consider applying the filter outside of
insert_hooked_blocks
, to keep it ignorant of$context
🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still need to document the filter in one place so it works with the documentation tool. What would be the benefit of having it repeated in all places where it has to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that aspect is definitely a tradeoff. The benefit would be separation of concerns; we would no longer need to pass
$context
toinsert_hooked_blocks
; I believe there's even a way to get rid of$relative_position
and$anchor_block
.However, I'm now also leaning to keep the filter inside
insert_hooked_blocks
, even though I don't love the mix of concerns.Another idea I had was to additionally extract an even finer-grained
insert_hooked_block
(singular), to have the best of both worlds. I might explore that separately.Note that I've started considering not merging this PR separately, but rather do it all as part of #5523. I've noticed that the ideal shape of helper functions is strongly determined by the eventual desired use case, which in this case includes insertion into modified layouts. I've noticed that "massaging" the function signatures and implementation into the right shape might lead to somewhat different results when done with those changes present, versus when done without them 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so you were concerned about the helper function signature. The thing is that you need to run the filter before you can serialize the block(s) into markup, so the helper makes less sense if you further break it down. Anyway, it might be fine to land the same changes with the original PR if that makes things simpler for you. This PR is still useful as we can discuss the problem in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding some test coverage for this (0b0f7cb), I became even more convinced that I didn't like
insert_block_hooks()
😬It's just weird: It takes a nested
$hooked_blocks
array, i.e. something likeplus an
$anchor_block
and a$relative_position
arg (among others), but only really looks up the hooked blocks that are relevant for that anchor block and relative position; any information about blocks hooked to other anchor blocks and/or relative positions is ignored. OTOH, that's also the only thing that the$relative_position
is used for.So I'd actually rather continue to duplicate the filter calls 😬
Instead, I filed a PR using the
insert_hooked_block
approach discussed here; although I ended up calling the function differently: #5712.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like your bad feelings about the excessive function's signature where spot on 👍🏻