Skip to content

Commit

Permalink
Feat: Handle source=HTML only block types
Browse files Browse the repository at this point in the history
  • Loading branch information
theodesp committed Apr 27, 2023
1 parent b4e0d9b commit 1ccf56c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions includes/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1ccf56c

Please sign in to comment.