mirrored from git://develop.git.wordpress.org/
-
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
Block Hooks: Set hooked block's layout attribute based on anchor block's #5811
Closed
ockham
wants to merge
2
commits into
WordPress:trunk
from
ockham:try/setting-layout-attr-based-on-sibling-block
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -771,9 +771,10 @@ function get_hooked_blocks() { | |
* | ||
* @param array $anchor_block The anchor block. Passed by reference. | ||
* @param string $hooked_block_type The name of the hooked block type. | ||
* @param array $attributes Optional. Attributes to pass to the hooked block. Default empty array. | ||
* @return string The markup for the given hooked block type, or an empty string if the block is ignored. | ||
*/ | ||
function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { | ||
function get_hooked_block_markup( &$anchor_block, $hooked_block_type, $attributes = array() ) { | ||
if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { | ||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); | ||
} | ||
|
@@ -786,7 +787,7 @@ function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { | |
// However, its presence does not affect the frontend. | ||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'][] = $hooked_block_type; | ||
|
||
return get_comment_delimited_block_content( $hooked_block_type, array(), '' ); | ||
return get_comment_delimited_block_content( $hooked_block_type, $attributes, '' ); | ||
} | ||
|
||
/** | ||
|
@@ -903,10 +904,28 @@ function make_after_block_visitor( $hooked_blocks, $context ) { | |
? $hooked_blocks[ $anchor_block_type ][ $relative_position ] | ||
: array(); | ||
|
||
if ( isset( $block['attrs']['layout'] ) ) { | ||
$layout = $block['attrs']['layout']; | ||
} | ||
|
||
/** This filter is documented in wp-includes/blocks.php */ | ||
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); | ||
foreach ( $hooked_block_types as $hooked_block_type ) { | ||
$markup .= get_hooked_block_markup( $block, $hooked_block_type ); | ||
$attributes = array(); | ||
|
||
// Does the anchor block have a layout attribute? | ||
if ( isset( $layout ) ) { | ||
// Has the hooked block type opted into layout block support? | ||
$hooked_block_type_obj = WP_Block_Type_Registry::get_instance()->get_registered( $hooked_block_type ); | ||
if ( $hooked_block_type_obj && $hooked_block_type_obj instanceof WP_Block_Type ) { | ||
if ( $hooked_block_type_obj->attributes && isset( $hooked_block_type_obj->attributes['layout'] ) ) { | ||
// Copy the anchor block's layout attribute to the hooked block. | ||
$attributes['layout'] = $layout; | ||
} | ||
} | ||
} | ||
|
||
$markup .= get_hooked_block_markup( $block, $hooked_block_type, $attributes ); | ||
Comment on lines
+914
to
+928
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. Note that this is only implemented for |
||
} | ||
|
||
if ( $parent_block && ! $next ) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not all blocks that support
layout
have the attribute explicitly declared; it only appears when the block has a non-default layout configuration. A more reliable check would beblock_has_support( $block_type, 'layout', false )
.