Skip to content

Commit

Permalink
Pattern Enhancements: Render unsynced pattern content (#50114)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw authored and glendaviesnz committed Apr 30, 2023
1 parent 00d381d commit 2e9ef80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/pattern/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/pattern/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }</>;
Expand Down
7 changes: 6 additions & 1 deletion test/integration/fixtures/blocks/core__pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
Expand Down

0 comments on commit 2e9ef80

Please sign in to comment.