From 2a8189dcfe18ecd8bc67d34c72f2b0a69841c0d2 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 24 Jul 2024 12:59:06 -0600 Subject: [PATCH 1/3] - ensure blocks have an ID if one is not set --- src/FieldConfig.php | 13 +++++++++++-- tests/_support/WPUnit/AcfFieldTestCase.php | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/FieldConfig.php b/src/FieldConfig.php index 67bf30a..ed7c1e5 100644 --- a/src/FieldConfig.php +++ b/src/FieldConfig.php @@ -447,10 +447,19 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI // resolve block field - if ( is_array( $node ) && isset( $node['blockName'] ) && isset( $node['attrs'] ) ) { - $block = acf_prepare_block( $node['attrs'] ); + if ( is_array( $node ) && isset( $node['blockName'], $node['attrs'] ) ) { + + $block = $node['attrs']; + + // Ensure the block has an ID + if ( ! isset( $block['id'] ) ) { + $block['id'] = uniqid( 'block_', true ); + } + + $block = acf_prepare_block( $block ); $block_id = acf_get_block_id( $node['attrs'] ); $block_id = acf_ensure_block_id_prefix( $block_id ); + acf_setup_meta( $block['data'], $block_id, true ); $return_value = $this->get_field( $field_config['name'], $parent_field_name, $block_id, $should_format_value ); diff --git a/tests/_support/WPUnit/AcfFieldTestCase.php b/tests/_support/WPUnit/AcfFieldTestCase.php index 7a8f601..8da9b3c 100644 --- a/tests/_support/WPUnit/AcfFieldTestCase.php +++ b/tests/_support/WPUnit/AcfFieldTestCase.php @@ -414,10 +414,10 @@ interfaces { ], ]); - codecept_debug([ - '$content' => $content, - '$parsed_blocks' => parse_blocks( $content ), - ]); +// codecept_debug([ +// '$content' => $content, +// '$parsed_blocks' => parse_blocks( $content ), +// ]); // assert the data is returned as expected self::assertQuerySuccessful( $actual, [ From 11b1eb6ae6aca1c25c1cee202a9b386b655218b9 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 24 Jul 2024 13:07:16 -0600 Subject: [PATCH 2/3] - cleanup --- src/FieldConfig.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/FieldConfig.php b/src/FieldConfig.php index ed7c1e5..375c27b 100644 --- a/src/FieldConfig.php +++ b/src/FieldConfig.php @@ -436,7 +436,6 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI return $pre_value; } - $parent_field = null; $parent_field_name = null; if ( ! empty( $field_config['parent'] ) ) { $parent_field = acf_get_field( $field_config['parent'] ); @@ -445,7 +444,6 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI } } - // resolve block field if ( is_array( $node ) && isset( $node['blockName'], $node['attrs'] ) ) { From c5f43cdfa148a7f6ac9bb32a8f40ae72cfaa6b52 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 24 Jul 2024 13:08:01 -0600 Subject: [PATCH 3/3] - fix-cs --- src/FieldConfig.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FieldConfig.php b/src/FieldConfig.php index 375c27b..624e85a 100644 --- a/src/FieldConfig.php +++ b/src/FieldConfig.php @@ -446,7 +446,6 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI // resolve block field if ( is_array( $node ) && isset( $node['blockName'], $node['attrs'] ) ) { - $block = $node['attrs']; // Ensure the block has an ID