Skip to content

Commit 4c6e695

Browse files
committed
- update FieldConfig to check for values prefixed with _ for resolution
- fix call to possibly unset `$parent_field_group['ID']` - phpstan fixes - update acf_get_raw_fields to acf_get_fields - add adjustments to how group types are registered if they've been cloned
1 parent ff391e8 commit 4c6e695

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

src/Admin/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function graphql_types_ajax_callback(): void {
159159
wp_send_json( __( 'No form data.', 'wpgraphql-acf' ) );
160160
}
161161

162-
if ( empty( $form_data ) || ! isset( $form_data['acf_field_group']['location'] ) ) {
162+
if ( empty( $form_data['acf_field_group']['location'] ) ) {
163163
wp_send_json( __( 'No field group locations found.', 'wpgraphql-acf' ) );
164164
}
165165

src/FieldConfig.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
409409
return $this->prepare_acf_field_value( $root[ $field_config['__key'] ], $node, $node_id, $field_config );
410410
}
411411

412+
// Else check if the values are being passed down via the name
413+
if ( isset( $field_config['name'] ) && ! empty( $root[ '_' . $field_config['name'] ] ) ) {
414+
return $this->prepare_acf_field_value( $root[ '_' . $field_config['name'] ], $node, $node_id, $field_config );
415+
}
416+
412417
// Else check if the values are being passed down via the name
413418
if ( isset( $field_config['name'] ) && ! empty( $root[ $field_config['name'] ] ) ) {
414419
return $this->prepare_acf_field_value( $root[ $field_config['name'] ], $node, $node_id, $field_config );
@@ -603,7 +608,7 @@ public function register_graphql_connections( array $config ): void {
603608
// Register the connection to the Field Group Type
604609
if ( defined( 'WPGRAPHQL_VERSION' ) && version_compare( WPGRAPHQL_VERSION, '1.23.0', '<=' ) ) {
605610
register_graphql_connection( $connection_config );
606-
}
611+
}
607612

608613
// Register the connection to the Field Group Fields Interface
609614
register_graphql_connection( array_merge( $connection_config, [ 'fromType' => $type_name . '_Fields' ] ) );

src/FieldType/FlexibleContent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ static function ( $field ) use ( $layout ) {
6969

7070
return isset( $field['parent_layout'] ) && $layout['key'] === $field['parent_layout'] ? $field : null;
7171
},
72-
acf_get_raw_fields( $layout['key'] )
72+
acf_get_fields( $layout['key'] )
7373
)
7474
);
7575

7676
$layout_sub_fields = ! empty( $layout['sub_fields'] ) && is_array( $layout['sub_fields'] ) ? $layout['sub_fields'] : [];
7777

7878
$layout['sub_fields'] = array_merge( $sub_fields, $layout_sub_fields );
79-
79+
8080
$layouts[] = $layout;
8181
}
8282
}

src/FieldType/Group.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ public static function register_field_type(): void {
3838
foreach ( $cloned_from['clone'] as $clone_field ) {
3939
$cloned_group = acf_get_field_group( $clone_field );
4040

41+
// if there is no cloned group, continue to the next clone field
4142
if ( ! $cloned_group ) {
4243
continue;
4344
}
4445

46+
// if the cloned group is not an ACF field group, continue to the next clone field
47+
if ( ! acf_is_field_group( $cloned_group ) ) {
48+
continue;
49+
}
50+
51+
// if the cloned group should not show in GraphQL, continue to the next clone field
4552
if ( ! $field_config->get_registry()->should_field_group_show_in_graphql( $cloned_group ) ) {
4653
continue;
4754
}
4855

56+
// determine the GraphQL Type of the cloned field group
4957
$cloned_type = $field_config->get_registry()->get_field_group_graphql_type_name( $cloned_group );
5058
break;
5159
}
@@ -55,7 +63,20 @@ public static function register_field_type(): void {
5563
// If the group is a clone field, return the cloned type instead of registering
5664
// another Type in the registry
5765
if ( $cloned_type ) {
58-
return Utils::format_type_name( $cloned_type . ' ' . $field_name );
66+
$cloned_type_name = Utils::format_type_name( $cloned_type . ' ' . $field_name );
67+
if ( $field_config->get_registry()->has_registered_field_group( $cloned_type_name ) ) {
68+
return $cloned_type_name;
69+
}
70+
71+
$sub_field_group['graphql_type_name'] = $cloned_type_name;
72+
$sub_field_group['graphql_field_name'] = $cloned_type_name;
73+
$field_config->get_registry()->register_acf_field_groups_to_graphql(
74+
[
75+
$sub_field_group,
76+
]
77+
);
78+
79+
return $cloned_type_name;
5980
}
6081

6182
$field_config->get_registry()->register_acf_field_groups_to_graphql(

src/Registry.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ protected function get_acf_fields( $parent_field_group ): array {
475475

476476
// Then check database.
477477
} else {
478-
$raw_fields = isset( $parent_field_group['ID'] ) ? acf_get_fields( $parent_field_group['ID'] ) : [];
478+
$parent_field_group_id = $parent_field_group['ID'] ?? null;
479+
$raw_fields = acf_get_raw_fields( $parent_field_group_id );
479480
foreach ( $raw_fields as $raw_field ) {
480481
$fields[] = $raw_field;
481482
}

0 commit comments

Comments
 (0)