Blocks: Revert implementation of block insertion functions.

In [56618], three functions (`insert_inner_block`, `prepend_inner_block`, and `append_inner_block`) were introduced. They were meant to be used for insertion of hooked blocks; however, it was discovered that the original idea wouldn't work for sibling insertion. Instead, a different approach will be taken (see #59412), and these functions are no longer needed and can thus be removed.

Reverts [56618].
See #59412, #59385, #59313.
Built from https://develop.svn.wordpress.org/trunk@56634


git-svn-id: http://core.svn.wordpress.org/trunk@56146 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2023-09-20 16:49:18 +00:00
parent b57af57210
commit 68be796e1d
2 changed files with 1 additions and 79 deletions

View File

@ -760,84 +760,6 @@ function get_hooked_blocks( $name ) {
return $hooked_blocks;
}
/**
* Insert a parsed block into a parent block's inner blocks.
*
* Given a parsed block, a block index, and a chunk index, insert another parsed block
* into the parent block at the given indices.
*
* Note that the this mutates the parent block by inserting into the parent's `innerBlocks`
* array, and by updating the parent's `innerContent` array accordingly.
*
* @since 6.4.0
*
* @param array $parent_block The parent block.
* @param int $block_index The index specifying the insertion position among the parent block's inner blocks.
* @param int $chunk_index The index specifying the insertion position among the parent block's inner content chunks.
* @param array $inserted_block The block to insert.
* @return void
*/
function insert_inner_block( &$parent_block, $block_index, $chunk_index, $inserted_block ) {
array_splice( $parent_block['innerBlocks'], $block_index, 0, array( $inserted_block ) );
/*
* Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`)
* when rendering blocks, we also need to insert a value (`null`, to mark a block
* location) into that array.
*/
array_splice( $parent_block['innerContent'], $chunk_index, 0, array( null ) );
}
/**
* Prepend a parsed block to a parent block's inner blocks.
*
* Given a parsed block, prepend another parsed block to the parent block's inner blocks.
*
* Note that the this mutates the parent block by inserting into the parent's `innerBlocks`
* array, and by updating the parent's `innerContent` array accordingly.
*
* @since 6.4.0
*
* @param array $parent_block The parent block.
* @param array $inserted_block The block to insert.
* @return void
*/
function prepend_inner_block( &$parent_block, $inserted_block ) {
$chunk_index = 0;
for ( $index = 0; $index < count( $parent_block['innerContent'] ); $index++ ) {
if ( is_null( $parent_block['innerContent'][ $index ] ) ) {
$chunk_index = $index;
break;
}
}
insert_inner_block( $parent_block, 0, $chunk_index, $inserted_block );
}
/**
* Append a parsed block to a parent block's inner blocks.
*
* Given a parsed block, append another parsed block to the parent block's inner blocks.
*
* Note that the this mutates the parent block by inserting into the parent's `innerBlocks`
* array, and by updating the parent's `innerContent` array accordingly.
*
* @since 6.4.0
*
* @param array $parent_block The parent block.
* @param array $inserted_block The block to insert.
* @return void
*/
function append_inner_block( &$parent_block, $inserted_block ) {
$chunk_index = count( $parent_block['innerContent'] );
for ( $index = count( $parent_block['innerContent'] ); $index > 0; $index-- ) {
if ( is_null( $parent_block['innerContent'][ $index - 1 ] ) ) {
$chunk_index = $index;
break;
}
}
insert_inner_block( $parent_block, count( $parent_block['innerBlocks'] ), $chunk_index, $inserted_block );
}
/**
* Given an array of attributes, returns a string in the serialized attributes
* format prepared for post content.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-alpha-56633';
$wp_version = '6.4-alpha-56634';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.