From 1ccf56c453b3ef6434a7e82d0a14ccec0cdac1d2 Mon Sep 17 00:00:00 2001 From: theodesp <328805+theodesp@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:03:58 +0100 Subject: [PATCH] Feat: Handle `source=HTML` only block types --- includes/Blocks/Block.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/Blocks/Block.php b/includes/Blocks/Block.php index c8e5d330..979a0836 100644 --- a/includes/Blocks/Block.php +++ b/includes/Blocks/Block.php @@ -73,7 +73,7 @@ public function __construct( WP_Block_Type $block, Registry $block_registry ) { * @return void */ public function register_fields() { } - + private function register_block_type() { $this->register_block_attributes_as_fields(); @@ -203,7 +203,21 @@ private function resolve( $block, array $args, AppContext $context, ResolveInfo private function resolve_block_attributes( $block, $attribute_name, $attribute_config ) { // Get default value. $default = isset( $attribute_config['default'] ) ? $attribute_config['default'] : null; - + // Case when only source defined: Classic Blocks + if ( isset( $attribute_config['source'] ) && ! isset( $attribute_config['selector'] ) ) { + $rendered_block = wp_unslash( render_block( $block ) ); + $value = null; + if ( empty( $rendered_block ) ) { + return $value; + } + switch ( $attribute_config['source'] ) { + case 'html': + $value = $rendered_block; + break; + } + return $value; + } + // Case when both selector and source are defined if ( isset( $attribute_config['selector'], $attribute_config['source'] ) ) { $rendered_block = wp_unslash( render_block( $block ) ); $value = null;