From 5924426fc8c8237a31ceeab886ccfe918a4b3b08 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Fri, 1 Dec 2023 11:41:45 +0800 Subject: [PATCH 1/2] Allow the heading block and the button block to be partially synced --- lib/experimental/blocks.php | 21 +++++++++++-------- packages/block-library/src/button/block.json | 3 ++- packages/block-library/src/heading/block.json | 3 ++- .../src/hooks/pattern-partial-syncing.js | 1 - packages/patterns/src/constants.js | 2 ++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/experimental/blocks.php b/lib/experimental/blocks.php index 88e46b478389d2..b72f3dabf95fbe 100644 --- a/lib/experimental/blocks.php +++ b/lib/experimental/blocks.php @@ -100,14 +100,17 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst // Allowlist of blocks that support block connections. // Currently, we only allow the following blocks and attributes: // - Paragraph: content. + // - Heading: content. + // - Button: text. // - Image: url. $blocks_attributes_allowlist = array( 'core/paragraph' => array( 'content' ), + 'core/heading' => array( 'content' ), + 'core/button' => array( 'text' ), 'core/image' => array( 'url' ), ); // Whitelist of the block types that support block connections. - // Currently, we only allow the Paragraph and Image blocks to use block connections. if ( ! in_array( $block['blockName'], array_keys( $blocks_attributes_allowlist ), true ) ) { return $block_content; } @@ -168,14 +171,14 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst continue; } - $tags = new WP_HTML_Tag_Processor( $block_content ); - $found = $tags->next_tag( - array( - // TODO: In the future, when blocks other than Paragraph and Image are - // supported, we should build the full query from CSS selector. - 'tag_name' => $block_type->attributes[ $attribute_name ]['selector'], - ) - ); + $selectors = explode( ',', $block_type->attributes[ $attribute_name ]['selector'] ); + $found = false; + while ( ! $found && count( $selectors ) > 0 ) { + $tags = new WP_HTML_Tag_Processor( $block_content ); + // TODO: In the future, when blocks are supported, + // we should build the full query from CSS selector. + $found = $tags->next_tag( trim( array_shift( $selectors ) ) ); + } if ( ! $found ) { return $block_content; } diff --git a/packages/block-library/src/button/block.json b/packages/block-library/src/button/block.json index eec327b4ca48e4..4286f200fda4b9 100644 --- a/packages/block-library/src/button/block.json +++ b/packages/block-library/src/button/block.json @@ -118,7 +118,8 @@ "width": true } }, - "__experimentalSelector": ".wp-block-button .wp-block-button__link" + "__experimentalSelector": ".wp-block-button .wp-block-button__link", + "__experimentalConnections": true }, "styles": [ { "name": "fill", "label": "Fill", "isDefault": true }, diff --git a/packages/block-library/src/heading/block.json b/packages/block-library/src/heading/block.json index 7c018f8472cb4a..2580eacc210425 100644 --- a/packages/block-library/src/heading/block.json +++ b/packages/block-library/src/heading/block.json @@ -63,7 +63,8 @@ } }, "__unstablePasteTextInline": true, - "__experimentalSlashInserter": true + "__experimentalSlashInserter": true, + "__experimentalConnections": true }, "editorStyle": "wp-block-heading-editor", "style": "wp-block-heading" diff --git a/packages/editor/src/hooks/pattern-partial-syncing.js b/packages/editor/src/hooks/pattern-partial-syncing.js index 40bd1e16dfc00d..fd47b0f20f5ee2 100644 --- a/packages/editor/src/hooks/pattern-partial-syncing.js +++ b/packages/editor/src/hooks/pattern-partial-syncing.js @@ -23,7 +23,6 @@ const { /** * Override the default edit UI to include a new block inspector control for * assigning a partial syncing controls to supported blocks in the pattern editor. - * Currently, only the `core/paragraph` block is supported. * * @param {Component} BlockEdit Original component. * diff --git a/packages/patterns/src/constants.js b/packages/patterns/src/constants.js index 3e533d834fd75c..82a92bc0af375c 100644 --- a/packages/patterns/src/constants.js +++ b/packages/patterns/src/constants.js @@ -23,4 +23,6 @@ export const PATTERN_SYNC_TYPES = { // TODO: This should not be hardcoded. Maybe there should be a config and/or an UI. export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = { 'core/paragraph': { content: __( 'Content' ) }, + 'core/heading': { content: __( 'Content' ) }, + 'core/button': { text: __( 'Text' ) }, }; From 2c014f64ac44a5c951223bc8751cd8a3d44c6d4e Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 19 Dec 2023 14:38:20 +0800 Subject: [PATCH 2/2] Update lib/experimental/blocks.php Co-authored-by: Daniel Richards --- lib/experimental/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/experimental/blocks.php b/lib/experimental/blocks.php index b72f3dabf95fbe..aec3bff964f234 100644 --- a/lib/experimental/blocks.php +++ b/lib/experimental/blocks.php @@ -175,7 +175,7 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst $found = false; while ( ! $found && count( $selectors ) > 0 ) { $tags = new WP_HTML_Tag_Processor( $block_content ); - // TODO: In the future, when blocks are supported, + // TODO: In the future, to support connecting more block attributes, // we should build the full query from CSS selector. $found = $tags->next_tag( trim( array_shift( $selectors ) ) ); }