Skip to content

Commit

Permalink
Revert "Add overrides attribute to pattern block and share it via pro…
Browse files Browse the repository at this point in the history
…videsContext"

This reverts commit aca9b906e676a16bfa117ebfaa406e9141b72817.
  • Loading branch information
talldan committed Jan 23, 2024
1 parent 5a95a4c commit a783aad
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Create and save content to reuse across your site. Update the pattern, and the c
- **Name:** core/block
- **Category:** reusable
- **Supports:** ~~customClassName~~, ~~html~~, ~~inserter~~, ~~renaming~~
- **Attributes:** overrides, ref
- **Attributes:** ref

## Button

Expand Down
6 changes: 0 additions & 6 deletions packages/block-library/src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@
"attributes": {
"ref": {
"type": "number"
},
"overrides": {
"type": "object"
}
},
"providesContext": {
"pattern/overrides": "overrides"
},
"supports": {
"customClassName": false,
"html": false,
Expand Down
48 changes: 48 additions & 0 deletions packages/block-library/src/block/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,32 @@ function render_block_core_block( $attributes ) {
global $wp_embed;
$content = $wp_embed->run_shortcode( $reusable_block->post_content );
$content = $wp_embed->autoembed( $content );

$gutenberg_experiments = get_option( 'gutenberg-experiments' );
$has_partial_synced_overrides = $gutenberg_experiments
&& array_key_exists( 'gutenberg-pattern-partial-syncing', $gutenberg_experiments )
&& isset( $attributes['overrides'] );

/**
* We set the `pattern/overrides` context through the `render_block_context`
* filter so that it is available when a pattern's inner blocks are
* rendering via do_blocks given it only receives the inner content.
*/
if ( $has_partial_synced_overrides ) {
$filter_block_context = static function ( $context ) use ( $attributes ) {
$context['pattern/overrides'] = $attributes['overrides'];
return $context;
};
add_filter( 'render_block_context', $filter_block_context, 1 );
}

$content = do_blocks( $content );
unset( $seen_refs[ $attributes['ref'] ] );

if ( $has_partial_synced_overrides ) {
remove_filter( 'render_block_context', $filter_block_context, 1 );
}

return $content;
}

Expand All @@ -63,3 +86,28 @@ function register_block_core_block() {
);
}
add_action( 'init', 'register_block_core_block' );

$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-partial-syncing', $gutenberg_experiments ) ) {
/**
* Registers the overrides attribute for core/block.
*
* @param array $args Array of arguments for registering a block type.
* @param string $block_name Block name including namespace.
* @return array $args
*/
function register_block_core_block_args( $args, $block_name ) {
if ( 'core/block' === $block_name ) {
$args['attributes'] = array_merge(
$args['attributes'],
array(
'overrides' => array(
'type' => 'object',
),
)
);
}
return $args;
}
add_filter( 'register_block_type_args', 'register_block_core_block_args', 10, 2 );
}

0 comments on commit a783aad

Please sign in to comment.