-
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
Testing: render_block_context
POC
#7420
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ class WP_Block { | |
* its registered type will be assigned to the block's `context` property. | ||
* | ||
* @since 5.5.0 | ||
* @since 6.7.0 Added the optional `$parent_block` argument. | ||
* | ||
* @param array $block { | ||
* An associative array of a single parsed block object. See WP_Block_Parser_Block. | ||
|
@@ -126,7 +127,7 @@ class WP_Block { | |
* @param array $available_context Optional array of ancestry context values. | ||
* @param WP_Block_Type_Registry $registry Optional block type registry. | ||
*/ | ||
public function __construct( $block, $available_context = array(), $registry = null ) { | ||
public function __construct( $block, $available_context = array(), $registry = null, $parent_block = null ) { | ||
$this->parsed_block = $block; | ||
$this->name = $block['blockName']; | ||
|
||
|
@@ -138,7 +139,7 @@ public function __construct( $block, $available_context = array(), $registry = n | |
|
||
$this->block_type = $registry->get_registered( $this->name ); | ||
|
||
$this->available_context = $available_context; | ||
$this->available_context = apply_filters( 'render_block_context', $available_context, $block, $parent_block ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is a POC, but just noting that if we proceed with implementing this, this will need the original filter comment doc to be added. |
||
|
||
if ( ! empty( $this->block_type->uses_context ) ) { | ||
foreach ( $this->block_type->uses_context as $context_name ) { | ||
|
@@ -159,7 +160,7 @@ public function __construct( $block, $available_context = array(), $registry = n | |
} | ||
} | ||
|
||
$this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry ); | ||
$this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry, $parent_block ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this right? Shouldn't the parent block of the inner blocks of this block be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No effect if i pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please clarify what you mean? How do you mean there's no effect? Logically, the child blocks should access their parent block. But by passing the parent block of the current block here to its child block(s), you're effectively passing the grandparent block, which seems wrong. |
||
} | ||
|
||
if ( ! empty( $block['innerHTML'] ) ) { | ||
|
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.
Question: How is
$parent_block
ever set here? Looking at the full function, it seems that it is only set tonull
at the top of the function, but then never changed. Will this always benull
? 🤔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 was introduce in https://core.trac.wordpress.org/changeset/51894 with message.
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.
Yes, but my question was how does this actually work? As far as I can tell
$parent_block
is alwaysnull
. Does it ever get populated with an actualWP_Block
instance anywhere?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 don't think. It always null for parent block.
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.
But then is that a bug? How does the parent block ever get set for any block?