From 54ae77347701e961a9b4076ce5f69beb0d994a3b Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:48:05 +1000 Subject: [PATCH] Pattern Enhancements: Render unsynced pattern content (#50114) --- docs/reference-guides/core-blocks.md | 4 ++-- packages/block-library/src/pattern/index.php | 9 +++++++-- packages/block-library/src/pattern/save.js | 1 + test/integration/fixtures/blocks/core__pattern.json | 7 ++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 55918738d0477a..a54a0c626a9192 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -482,8 +482,8 @@ Show a block pattern. ([Source](https://github.com/WordPress/gutenberg/tree/trun - **Name:** core/pattern - **Category:** theme -- **Supports:** ~~html~~, ~~inserter~~ -- **Attributes:** slug, unsynced +- **Supports:** align (full, wide) +- **Attributes:** align, layout, slug, syncStatus ## Post Author diff --git a/packages/block-library/src/pattern/index.php b/packages/block-library/src/pattern/index.php index 32a08601ca8089..b60df3d43fdcea 100644 --- a/packages/block-library/src/pattern/index.php +++ b/packages/block-library/src/pattern/index.php @@ -22,15 +22,20 @@ function register_block_core_pattern() { /** * Renders the `core/pattern` block on the server. * - * @param array $attributes Block attributes. + * @param array $attributes Block attributes. + * @param string $content The block rendered content. * * @return string Returns the output of the pattern. */ -function render_block_core_pattern( $attributes ) { +function render_block_core_pattern( $attributes, $content ) { if ( empty( $attributes['slug'] ) ) { return ''; } + if ( isset( $attributes['syncStatus'] ) && 'unsynced' === $attributes['syncStatus'] ) { + return $content; + } + $slug = $attributes['slug']; $registry = WP_Block_Patterns_Registry::get_instance(); if ( ! $registry->is_registered( $slug ) ) { diff --git a/packages/block-library/src/pattern/save.js b/packages/block-library/src/pattern/save.js index 05c3328904c45b..a58adc56f80067 100644 --- a/packages/block-library/src/pattern/save.js +++ b/packages/block-library/src/pattern/save.js @@ -7,6 +7,7 @@ export default function save( { attributes } ) { if ( attributes.syncStatus === 'synced' ) { return null; } + const blockProps = useBlockProps.save(); const innerBlocksProps = useInnerBlocksProps.save( blockProps ); return <>{ innerBlocksProps.children }; diff --git a/test/integration/fixtures/blocks/core__pattern.json b/test/integration/fixtures/blocks/core__pattern.json index 3bb2c0891b06ec..a92b57163082f0 100644 --- a/test/integration/fixtures/blocks/core__pattern.json +++ b/test/integration/fixtures/blocks/core__pattern.json @@ -3,7 +3,12 @@ "name": "core/pattern", "isValid": true, "attributes": { - "slug": "core/text-two-columns" + "align": "full", + "layout": { + "type": "constrained" + }, + "slug": "core/text-two-columns", + "syncStatus": "synced" }, "innerBlocks": [] }