@@ -287,33 +287,33 @@ public function get_field_group_interfaces( array $acf_field_group ): array {
287287 $ raw_fields = acf_get_raw_fields ( $ acf_field_group ['ID ' ] );
288288 }
289289
290- // $cloned_groups = [];
291- // if ( ! empty( $raw_fields ) ) {
292- // foreach ( $raw_fields as $raw_field ) {
293- // if ( empty( $raw_field['clone'] ) || ! is_array( $raw_field['clone'] ) ) {
294- // continue;
295- // }
296- // foreach ( $raw_field['clone'] as $cloned_field ) {
297- // if ( ! acf_get_field_group( $cloned_field ) ) {
298- // continue;
299- // }
300- //
301- // if ( ! in_array( $cloned_field, $cloned_groups, true ) ) {
302- // $cloned_groups[] = $cloned_field;
303- // }
304- // }
305- // }
306- // }
307- //
308- // if ( ! empty( $cloned_groups ) ) {
309- // foreach ( $cloned_groups as $cloned_group ) {
310- // $cloned_group = acf_get_field_group( $cloned_group );
311- // if ( empty( $cloned_group ) ) {
312- // continue;
313- // }
314- // // $interfaces[] = $this->get_field_group_graphql_type_name( $cloned_group ) . '_Fields';
315- // }
316- // }
290+ $ cloned_groups = [];
291+ if ( ! empty ( $ raw_fields ) ) {
292+ foreach ( $ raw_fields as $ raw_field ) {
293+ if ( empty ( $ raw_field ['clone ' ] ) || ! is_array ( $ raw_field ['clone ' ] ) ) {
294+ continue ;
295+ }
296+ foreach ( $ raw_field ['clone ' ] as $ cloned_field ) {
297+ if ( ! acf_get_field_group ( $ cloned_field ) ) {
298+ continue ;
299+ }
300+
301+ if ( ! in_array ( $ cloned_field , $ cloned_groups , true ) ) {
302+ $ cloned_groups [] = $ cloned_field ;
303+ }
304+ }
305+ }
306+ }
307+
308+ if ( ! empty ( $ cloned_groups ) ) {
309+ foreach ( $ cloned_groups as $ cloned_group ) {
310+ $ cloned_group = acf_get_field_group ( $ cloned_group );
311+ if ( empty ( $ cloned_group ) ) {
312+ continue ;
313+ }
314+ $ interfaces [] = $ this ->get_field_group_graphql_type_name ( $ cloned_group ) . '_Fields ' ;
315+ }
316+ }
317317 }
318318
319319 $ interfaces = array_unique ( array_values ( $ interfaces ) );
@@ -465,41 +465,34 @@ public function get_fields_for_field_group( array $acf_field_group ): array {
465465 continue ;
466466 }
467467
468- // if ( defined( 'ACF_PRO' ) && ! empty( $acf_field['_clone'] ) && ! empty( $acf_field['__key'] ) ) {
469- // $cloned_fields[ $graphql_field_name ] = $acf_field;
470- //
471- // // if the clone field is not in the array of cloned fields
472- // if ( ! in_array( $acf_field['__key'], $_cloned_fields, true ) ) {
473- // $cloned_from = $acf_field;
474- // $acf_field = acf_get_field( $acf_field['__key'] );
475- // if ( empty( $acf_field ) ) {
476- // continue;
477- // }
478- // $acf_field['__key'] = $cloned_from['key'];
479- // }
480- // }
468+ if ( defined ( 'ACF_PRO ' ) && ! empty ( $ acf_field ['_clone ' ] ) && ! empty ( $ acf_field ['__key ' ] ) ) {
469+ $ cloned_fields [ $ graphql_field_name ] = $ acf_field ;
470+
471+ // if the clone field is not in the array of cloned fields
472+ if ( ! in_array ( $ acf_field ['__key ' ], $ _cloned_fields , true ) ) {
473+ $ cloned_from = $ acf_field ;
474+ $ acf_field = acf_get_field ( $ acf_field ['__key ' ] );
475+ if ( empty ( $ acf_field ) ) {
476+ continue ;
477+ }
478+ $ acf_field ['__key ' ] = $ cloned_from ['key ' ];
479+ }
480+ }
481481
482482 $ field_config = $ this ->map_acf_field_to_graphql ( $ acf_field , $ acf_field_group );
483483
484484 $ graphql_fields [ $ graphql_field_name ] = $ field_config ;
485485 }
486486
487- // if ( 'customContent' === $acf_field_group['graphql_field_name'] ) {
488- // wp_send_json( [
489- // '$fields' => $fields,
490- // '$graphql_fields' => $graphql_fields,
491- // ]);
492- // }
493-
494- // // If there are cloned fields, pass the cloned field key to the field config for use in resolution
495- // if ( defined( 'ACF_PRO' ) && ! empty( $cloned_fields ) ) {
496- // foreach ( $cloned_fields as $cloned_field ) {
497- // $graphql_field_name = $this->get_graphql_field_name( $cloned_field );
498- // if ( isset( $graphql_fields[ $graphql_field_name ] ) ) {
499- // $graphql_fields[ $graphql_field_name ]['acf_field']['__key'] = $cloned_field['key'];
500- // }
501- // }
502- // }
487+ // If there are cloned fields, pass the cloned field key to the field config for use in resolution
488+ if ( defined ( 'ACF_PRO ' ) && ! empty ( $ cloned_fields ) ) {
489+ foreach ( $ cloned_fields as $ cloned_field ) {
490+ $ graphql_field_name = $ this ->get_graphql_field_name ( $ cloned_field );
491+ if ( isset ( $ graphql_fields [ $ graphql_field_name ] ) ) {
492+ $ graphql_fields [ $ graphql_field_name ]['acf_field ' ]['__key ' ] = $ cloned_field ['key ' ];
493+ }
494+ }
495+ }
503496
504497 return $ graphql_fields ;
505498 }
0 commit comments