-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Notes: Fix 'children' embedding via REST API #72561
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
Conversation
05c6482 to
e213526
Compare
| $args = array( | ||
| 'parent' => $comment->comment_ID, | ||
| 'type' => $comment->comment_type, | ||
| 'status' => 'all', |
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.
Currently, embedded replies are missing a couple of properties, such as content.raw and meta.
I know that links can pass their own context, but I haven't seen it used in practice by core. Is this something we should avoid?
P.S. What's the reason for disallowing embed context for specific properties, but allowing it in view context? Wasn't able to find anything in the docs.
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.
such as content.raw
We wouldn't include content.raw, because it's an edit only property. The embed should be a subset of view.
I know that links can pass their own context, but I haven't seen it used in practice by core. Is this something we should avoid?
Yeah, I wouldn't want us to introduce that to Core, because that's really something that the client should be deciding on.
I wouldn't be opposed to something like ?_embed=children.view perhaps? Maybe that's too cheeky of an API.
What's the reason for disallowing embed context for specific properties, but allowing it in view context?
Ultimately, it's a judgement call about payload size/cost and importance. The embed context is often thought of as being used in a context (ha) where you are displaying a small snippet of a resource, and then would often link to a view where you can see everything about a resource.
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 think we can still make it work without content.raw. We could refetch the note that the user is editing with proper context, or just use content.rendered. The form currently lacks RichText capabilities.
The meta values are used for display, so we'll need to fetch them. It would have been nice if each meta property could define its context, if needed.
Ultimately, it's a judgement call about payload size/cost and importance. The embed context is often thought of as being used in a context (ha) where you are displaying a small snippet of a resource, and then would often link to a view where you can see everything about a resource.
Thanks for the explanation. The logic now makes sense.
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 would have been nice if each meta property could define its context, if needed.
They can in their show_in_rest schema definition. I've always used it to add an edit context and hide the value. I think we could safely extend the context for meta to include embed as a value, and then automatically apply a default context of view,edit for each meta key.
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.
Really? I tried setting a custom context for these meta fields, but it wasn't available in the embed response.
The meta fields object has its context set to view,edit, and I don't think you can override it without changing the REST API code.
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.
Right, at the moment, it only works to constrain it further. So I'm suggesting we add embed to the context list for meta. And when build up the properties schema here we add a default context of view,edit. That way, any existing meta keys continue to not show up in an embed 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.
Got it. However, that's probably something for the next major release. But I'll create a ticket and patch on Trac.
Do you think that the current children link fix makes sense to include with the current release, even if we don't end up using embedded values?
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.
Yep, I think so. It looks like a valid bug fix to me.
e213526 to
72c6616
Compare
|
Flaky tests detected in 72c6616. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18743459196
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
72c6616 to
b8a7e37
Compare
|
I'm going to merge this after all checks pass. @adamsilverstein is working on backports. |
|
@Mamaduka Does this need the 6.9 backport label or expected to have this pulled into the wordpress-develop work that @adamsilverstein is working on? |
|
@jeffpaul, this should be part of WordPress/wordpress-develop#10405 (comment). |
|
@jeffpaul - I am pulling this in manually. |
What?
Requires #71728.
Related #71668 (comment).
PR overrides the
childrenembeddable link for notes to allow embedding their replies (children). The current link returns no results because it uses the defaulttypeandstatuscollection params, instead of inheriting from the current query.An alternative option is to add a new
replieslink just for thenotecomment type and not modify the existing one, but considering we're already patching responses for the Notes, I don't think this is a breaking change.Why?
See #71668 (comment).
Testing Instructions
add_action( 'comments_clauses', 'exclude_block_comments_from_admin', 10, 2 );.Test JS snippet
Testing Instructions for Keyboard
Same.
Screeenshot