Skip to content
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

Pattern block: update frontend render code to match the new version of syncStatus attrib #50646

Merged
merged 4 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions packages/block-library/src/pattern/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@ function register_block_core_pattern() {
/**
* Renders the `core/pattern` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content The block rendered content.
* @param array $attributes Block attributes.
*
* @return string Returns the output of the pattern.
*/
function render_block_core_pattern( $attributes, $content ) {
function render_block_core_pattern( $attributes ) {
if ( empty( $attributes['slug'] ) ) {
return '';
}
$slug_classname = str_replace( '/', '-', $attributes['slug'] );
$classnames = isset( $attributes['className'] ) ? $attributes['className'] . ' ' . $slug_classname : $slug_classname;
$wrapper = '<div class="' . esc_attr( $classnames ) . '">%s</div>';

if ( isset( $attributes['syncStatus'] ) && 'unsynced' === $attributes['syncStatus'] ) {
return sprintf( $wrapper, $content );
}

$slug = $attributes['slug'];
$registry = WP_Block_Patterns_Registry::get_instance();

if ( ! $registry->is_registered( $slug ) ) {
return '';
}

$pattern = $registry->get_registered( $slug );

// Currently all existing blocks should be returned here without a wp-block-pattern wrapper
// as the syncStatus attribute is only used if the gutenberg-pattern-enhancements experiment
// is enabled.
if ( ! isset( $attributes['syncStatus'] ) ) {
return do_blocks( $pattern['content'] );
}

$block_classnames = 'wp-block-pattern ' . str_replace( '/', '-', $attributes['slug'] );
$classnames = isset( $attributes['className'] ) ? $attributes['className'] . ' ' . $block_classnames : $block_classnames;
$wrapper = '<div class="' . esc_attr( $classnames ) . '">%s</div>';

return sprintf( $wrapper, do_blocks( $pattern['content'] ) );
}

Expand Down