Skip to content

Commit

Permalink
Parse (area-specific) context in template-part block. (#47203)
Browse files Browse the repository at this point in the history
* Parse (area-specific) context in template-part block.

* Fix WPCS violations.

* Update context name to drop the_ prefix.
  • Loading branch information
felixarntz authored Jan 23, 2023
1 parent 2251f11 commit ea4af80
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,39 @@ function render_block_core_template_part( $attributes ) {
'';
}

// Look up area definition.
$area_definition = null;
$defined_areas = get_allowed_block_template_part_areas();
foreach ( $defined_areas as $defined_area ) {
if ( $defined_area['area'] === $area ) {
$area_definition = $defined_area;
break;
}
}

// If $area is not allowed, set it back to the uncategorized default.
if ( ! $area_definition ) {
$area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
}

// Run through the actions that are typically taken on the_content.
$seen_ids[ $template_part_id ] = true;
$content = do_blocks( $content );
unset( $seen_ids[ $template_part_id ] );
$content = wptexturize( $content );
$content = convert_smilies( $content );
$content = shortcode_unautop( $content );
$content = wp_filter_content_tags( $content );
$content = wp_filter_content_tags( $content, "template_part_{$area}" );
$content = do_shortcode( $content );

// Handle embeds for block template parts.
global $wp_embed;
$content = $wp_embed->autoembed( $content );

if ( empty( $attributes['tagName'] ) ) {
$defined_areas = get_allowed_block_template_part_areas();
$area_tag = 'div';
foreach ( $defined_areas as $defined_area ) {
if ( $defined_area['area'] === $area && isset( $defined_area['area_tag'] ) ) {
$area_tag = $defined_area['area_tag'];
}
$area_tag = 'div';
if ( $area_definition && isset( $area_definition['area_tag'] ) ) {
$area_tag = $area_definition['area_tag'];
}
$html_tag = $area_tag;
} else {
Expand Down

1 comment on commit ea4af80

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ea4af80.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3986318548
📝 Reported issues:

Please sign in to comment.