Skip to content

Commit 2a8189d

Browse files
committed
- ensure blocks have an ID if one is not set
1 parent 170980f commit 2a8189d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/FieldConfig.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,19 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
447447

448448

449449
// resolve block field
450-
if ( is_array( $node ) && isset( $node['blockName'] ) && isset( $node['attrs'] ) ) {
451-
$block = acf_prepare_block( $node['attrs'] );
450+
if ( is_array( $node ) && isset( $node['blockName'], $node['attrs'] ) ) {
451+
452+
$block = $node['attrs'];
453+
454+
// Ensure the block has an ID
455+
if ( ! isset( $block['id'] ) ) {
456+
$block['id'] = uniqid( 'block_', true );
457+
}
458+
459+
$block = acf_prepare_block( $block );
452460
$block_id = acf_get_block_id( $node['attrs'] );
453461
$block_id = acf_ensure_block_id_prefix( $block_id );
462+
454463
acf_setup_meta( $block['data'], $block_id, true );
455464

456465
$return_value = $this->get_field( $field_config['name'], $parent_field_name, $block_id, $should_format_value );

tests/_support/WPUnit/AcfFieldTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ interfaces {
414414
],
415415
]);
416416

417-
codecept_debug([
418-
'$content' => $content,
419-
'$parsed_blocks' => parse_blocks( $content ),
420-
]);
417+
// codecept_debug([
418+
// '$content' => $content,
419+
// '$parsed_blocks' => parse_blocks( $content ),
420+
// ]);
421421

422422
// assert the data is returned as expected
423423
self::assertQuerySuccessful( $actual, [

0 commit comments

Comments
 (0)