-
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
Add back providesContext block attribute #23212
Conversation
lib/class-wp-block.php
Outdated
@@ -107,8 +107,8 @@ public function __construct( $block, $available_context = array(), $registry = n | |||
|
|||
$this->available_context = $available_context; | |||
|
|||
if ( ! empty( $this->block_type->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.
does anyone know is this is used anywhere else? I unfortunately am not familiar with block context 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.
It should be rather usesContext
, it doesn't error when this context is not provided.
We would need to update all occurrences of context
in block.json
files of core blocks.
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.
Why? Isn't this just an internal switch which parses context
from block.json, turns it into usesContext
, and then the WPBlock
class takes usesContext
to set the context
property on itself?
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.e. doesn't the external API stay the same?
Size Change: 0 B Total Size: 1.13 MB ℹ️ View Unchanged
|
Related PR #22686. Depending on what we agree upon here, it should be updated within the linked PR. @aduth, @epiqueras or @mcsf might have the best knowledge on what's the best name for this property and what parts of the codebase might need to be updated. I assume it's only used in PHP codebase. I'm curious if it was already backported to WordPress core. |
Ideally, |
sigh. I feel like this is turning into a rabbit hole which I'm not super interested in going down. :p The initial work to do this conversion left out block context, which broke dynamic blocks which used it (and
I hope no one started using context outside of Gutenberg. :p I do think that
I completely agree. Is this normal in WordPress? |
Hard disagree on shadowing the Besides being confusing, the request object doesn't differentiate between query args and body params. So this would give incredibly odd behavior if we ever were to provide the |
Sounds like we need to rename it to |
If #23212 (comment) is true, then let's merge this for now as a fix at least. cc @gziolo |
that sounds good to me. |
This PR is a duplicate of #22686 isn't it? |
Unfortunately, renaming this would make backward compatibility really hard. Can we keep |
I have no issue with that from the REST API perspective. |
I'm not 100% sure, but is this what's happening right now? You still specify This just changes the registration property, which is then parsed into At least that's my reading. If that's correct, I think these changes can be pretty minimal.
🤷 I think they accomplish two different things. This makes sure that |
That PR is handling the block type properties for the REST endpoint. I still think we should keep |
I see what you mean. That makes sense to me. I'll just update this to only add back the |
c416efa
to
94c9b2a
Compare
@epiqueras, how hard is really hard? Right now, context is still a pretty new concept, and only lives in the Gutenberg plugin. If there is a time to rename it so as to keep JS-PHP consistency, it's likely now. We could make it Edit: for reference, Trac ticket 49927 is still open. |
Given that PHP linter warns about camelCase used in One of the tests fails on Travis and it might be an actual issue because it's related to template parts:
Let's merge this PR once this test passes. |
So deprecate |
Yes, it seems like |
Should I still merge this PR as is for now? |
94c9b2a
to
1912fe4
Compare
Just waiting for Travis to be happy. |
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.
Please change providesContex
t to provides_context
.
In PHP, snake case is not allowed.
'title' => 'title', | ||
'category' => 'category', | ||
'context' => 'context', | ||
'providesContext' => 'providesContext', |
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.
'providesContext' => 'providesContext', | |
'providesContext' => 'provides_context', |
I think I sorted out everything in #22686 to have |
@noahtallen, thank you for all work on this issue. It's a very difficult issue to solve :( |
Description
providesContext
mapping (see Add context property mapping to block registration #23180)Note: converting
context
touses_context
andprovidesContext
toprovides_context
will happen at the API level in #22686.How has this been tested?
Locally in edit site. Made sure block context still works for dynamic blocks.
Screenshots
Types of changes
Bug fix
Checklist: