-
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
Block API: Block Context: Filter content, prepare attributes at render, pass block to render #21925
Conversation
Size Change: +4.91 kB (0%) Total Size: 821 kB
ℹ️ View Unchanged
|
4ac2be1
to
52db02b
Compare
I force-pushed a rebase to resolve conflicts introduced by #21921. I'll plan to continue iterating on this tomorrow. |
I pushed a few more commits here, experimenting with a couple extra ideas noted in the original pull request comment and from #21797 (comment), largely dealing with the "issue" of
To reiterate, both of these are optional enhancements, and can be assessed independently. Also, the (cc @noisysocks, my new go-to anti-magic mentor 😄) |
🤣 |
Include inner blocks as a noted previous regression
Co-authored-by: Enrique Piqueras <[email protected]>
This is feeling quite stable now, and I'd like to let this sit in It's also a potential blocker for a related issue #22100. |
Great work! |
Sorry I was MIA! I appreciate the new title you've given me 😛 Yes, it's a little atypical in PHP to implement I think it's fine here and I like how it makes e.g. My only concern is that IDEs won't know about I like the |
Thanks @noisysocks ! And speaking as someone who has a tendency to comment on years-old pull requests, I'd be the last person to reject feedback after-the-fact 😄
For me, one of the other lesser objectives here was also to bring consistency between server-side and client-side interfaces, summarized earlier at #21467 (comment).
I was pretty disappointed about this as well. In fact, in early iterations, I kept the I wasn't familiar with the |
Backports functionality added in Gutenberg in the following PRs: - WordPress/gutenberg#21467 - WordPress/gutenberg#21925 It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context. Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan. Fixes #49926. git-svn-id: https://develop.svn.wordpress.org/trunk@48159 602fd350-edb4-49c9-b593-d223f7449a82
Backports functionality added in Gutenberg in the following PRs: - WordPress/gutenberg#21467 - WordPress/gutenberg#21925 It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context. Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan. Fixes #49926. git-svn-id: https://develop.svn.wordpress.org/trunk@48159 602fd350-edb4-49c9-b593-d223f7449a82
Backports functionality added in Gutenberg in the following PRs: - WordPress/gutenberg#21467 - WordPress/gutenberg#21925 It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context. Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan. Fixes #49926. Built from https://develop.svn.wordpress.org/trunk@48159 git-svn-id: http://core.svn.wordpress.org/trunk@47928 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Backports functionality added in Gutenberg in the following PRs: - WordPress/gutenberg#21467 - WordPress/gutenberg#21925 It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context. Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan. Fixes #49926. Built from https://develop.svn.wordpress.org/trunk@48159 git-svn-id: https://core.svn.wordpress.org/trunk@47928 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Backports functionality added in Gutenberg in the following PRs: - WordPress/gutenberg#21467 - WordPress/gutenberg#21925 It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context. Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan. Fixes #49926. git-svn-id: https://develop.svn.wordpress.org/trunk@48159 602fd350-edb4-49c9-b593-d223f7449a82
Related: #21921
Closes #21797
Note: This pull request is intended to be exploratory, related to discussion In #21797 in how best to make available block context and block values in general.Edit: Stability achieved after continued iteration and feedback cycles.This pull request seeks to explore a few ideas related to block rendering and the provided block value, which is particularly impactful for ongoing work around block context.
It...
render_block
filter inWP_Block::render
, intended to address the bug separately addressed in Block API: Block Context: Remove block filter #21921render_callback
not fully backward-compatible as array #21797 (comment)$block
value, since$block->attributes
will be the attributes as parsed, not including any defaults. I haven't yet experimented with it, but the__get
magic method usage described in Block API: Block contextrender_callback
not fully backward-compatible as array #21797 (comment) could be a reasonable compromise here.prepare_attributes_for_render
is only called when a block is rendered. However, the proposed benefits of the changes in Block API: Add Block Context support #21467 were partly to soft-deprecate this, and intentionally change to a behavior which was more "predictable" as far as attributes always being defaulted once the class instance is constructed.render_callback
not fully backward-compatible as array #21797 (comment), was not included as part of these changes. It would probably be necessary to keep this in the constructor, at least given how context is currently prepared and passed to descendants using constructor arguments.$block
class instance as a third argument ofrender_callback
prepare_attributes_for_render
is deferred to the point that the block is rendered.Testing Instructions:
Repeat testing instructions from #21921.
Ensure unit tests pass: