-
Notifications
You must be signed in to change notification settings - Fork 1
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
Issue-64: extract pre_render_block logic #78
Issue-64: extract pre_render_block logic #78
Conversation
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.
Left some questions and suggestions, no blockers 🍣
@@ -27,36 +32,10 @@ function wp_conditional_blocks_is_false_block_init(): void { | |||
* Short-circuit the display of blocks inside if the outer condition isn't false. | |||
* | |||
* @param string|null $pre_render The pre-rendered content. Default null. | |||
* @param WP_Block $parsed_block The block being rendered. | |||
* @param mixed[] $parsed_block The block being rendered. |
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.
Can $parsed_block
contain other items in the array besides WP_Block
objects? What are they?
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.
Parsed block is an array containing (at times) the blockName
, attrs
, innerBlocks
, innerHTML
, and innerContent
of the block we are rendering. Its never a WP_Block
object, as far as I can tell.
if ( ! isset( $parsed_block['blockName'] ) ) { | ||
return false; | ||
} | ||
|
||
return $block_name === $parsed_block['blockName']; |
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.
if ( ! isset( $parsed_block['blockName'] ) ) { | |
return false; | |
} | |
return $block_name === $parsed_block['blockName']; | |
return isset( $parsed_block['blockName'] ) && $block_name === $parsed_block['blockName']; |
if ( ! ( $parent_block instanceof WP_Block ) ) { | ||
return false; | ||
} | ||
|
||
return is_active_block( $block_name, $parent_block->parsed_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.
if ( ! ( $parent_block instanceof WP_Block ) ) { | |
return false; | |
} | |
return is_active_block( $block_name, $parent_block->parsed_block ); | |
return $parent_block instanceof WP_Block && is_active_block( $block_name, $parent_block->parsed_block ); |
$context['postId'] = $parent_block->context['postId']; | ||
} | ||
|
||
if ( wp_conditional_blocks_condition_block_result( $parent_block->parsed_block, $context ) !== $bool ) { // @phpstan-ignore-line |
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 is PHPStan unhappy here?
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.
Its not able to tell that $parent_block is an object because the check happens in a function.
Summary
This pull request addresses the issue described in #64. It aims to refactor the pre_render_block filter logic used in both is-false and is-true blocks into reusable functions to adhere to the DRY (Don't Repeat Yourself) principle.
Fixes #64
Changes
Testing
Documentation
Notes