Skip to content

Commit

Permalink
Post Content block: Allow Block Hooks child insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Dec 8, 2023
1 parent 308fc42 commit 12d8bca
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion packages/block-library/src/post-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,47 @@ function render_block_core_post_content( $attributes, $content, $block ) {

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );

// Allow `first_child` and `last_child` insertion.
// As the Post Content block simply renders the markup returned by the
// `get_the_content()` function (wrapped in a `<div>` block wrapper),
// Limitations:
// - Changes to anchor block by get_hooked_block_markup() aren't respected.
// - No $context available.

$context = null;

Check warning on line 64 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 11 spaces but found 14 spaces
$anchor_block_type = 'core/post-content';

Check warning on line 65 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 1 space but found 4 spaces
$anchor_block = array(

Check warning on line 66 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces
'blockName' => $anchor_block_type,
'attributes' => $attributes

Check failure on line 68 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

There should be a comma after the last array item in a multi-line array.
);
$hooked_blocks = get_hooked_blocks();

Check warning on line 70 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 8 spaces

$first_child_markup = '';

Check warning on line 72 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
$hooked_block_types_first_child = isset( $hooked_blocks[ $anchor_block_type ]['first_child'] )
? $hooked_blocks[ $anchor_block_type ]['first_child']
: array();

$hooked_block_types_first_child = apply_filters( 'hooked_block_types', $hooked_block_types_first_child, 'first_child', $anchor_block_type, $context );
foreach ( $hooked_block_types_first_child as $hooked_block_type_first_child ) {
$first_child_markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type_first_child );
}

// TODO: Should run `get_the_content` and apply `the_content` filter here.

$last_child_markup = '';

Check warning on line 84 in packages/block-library/src/post-content/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
$hooked_block_types_last_child = isset( $hooked_blocks[ $anchor_block_type ]['last_child'] )
? $hooked_blocks[ $anchor_block_type ]['last_child']
: array();

$hooked_block_types_last_child = apply_filters( 'hooked_block_types', $hooked_block_types_last_child, 'last_child', $anchor_block_type, $context );
foreach ( $hooked_block_types_last_child as $hooked_block_type_last_child ) {
// $parent_block should be a reference. That's an array. Tricky.
$last_child_markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type_last_child );
}

return (
'<div ' . $wrapper_attributes . '>' .
$content .
$first_child_markup . $content . $last_child_markup .
'</div>'
);
}
Expand Down

0 comments on commit 12d8bca

Please sign in to comment.