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 Enhancements: Render unsynced pattern content #50114

Merged
Show file tree
Hide file tree
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
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