Skip to content

Commit 64a3358

Browse files
committed
Revert "- initial exploration of fixing the issue. . .debugging"
This reverts commit 3a22eba.
1 parent 3a22eba commit 64a3358

File tree

4 files changed

+50
-87
lines changed

4 files changed

+50
-87
lines changed

src/AcfGraphQLFieldType.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ public function get_resolve_type( FieldConfig $field_config ) {
327327
return $resolve_type;
328328
}
329329

330-
// if ( [ 'list_of' => 'AcfProKitchenSinkFlexibleContentClonedRepeater' ] === $resolve_type ) {
331-
//// wp_send_json( [
332-
//// '$resolve_type' => $resolve_type,
333-
//// ]);
334-
//
335-
// // register_graphql_interfaces_to_types( ['InactiveGroupForCloningClonedRepeater'], [ 'AcfProKitchenSinkFlexibleContentClonedRepeater' ]);
336-
// }
337-
338330
// If the ACF Field is set to "graphql_non_null", map it to the schema as non_null
339331
if ( isset( $acf_field['graphql_non_null'] ) && true === (bool) $acf_field['graphql_non_null'] ) {
340332
$resolve_type = [ 'non_null' => $resolve_type ];

src/FieldType/CloneField.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
22
namespace WPGraphQL\Acf\FieldType;
33

4-
use WPGraphQL\Acf\AcfGraphQLFieldType;
5-
use WPGraphQL\Acf\FieldConfig;
6-
74
class CloneField {
85

96
/**
@@ -13,6 +10,7 @@ public static function register_field_type():void {
1310
register_graphql_acf_field_type(
1411
'clone',
1512
[
13+
1614
// The clone field adds its own settings field to display
1715
'admin_fields' => static function ( $default_admin_settings, $field, $config, \WPGraphQL\Acf\Admin\Settings $settings ) {
1816

src/FieldType/FlexibleContent.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,6 @@ static function ( $field ) use ( $layout ) {
7373

7474
// Add the layout interface name as an interface. This is the type that is returned as a list of for accessing all layouts of the flex field
7575
$interfaces[] = $layout_interface_name;
76-
77-
78-
if ( ! empty( $acf_field['_clone'] ) && ! empty( $acf_field['__key'] ) ) {
79-
$cloned_from = acf_get_field( $acf_field['__key'] );
80-
$cloned_parent_type = $field_config->get_parent_graphql_type_name( $cloned_from );
81-
$cloned_field_name = $field_config->get_registry()->get_graphql_field_name( $cloned_from );
82-
$cloned_layout_interface_prefix = Utils::format_type_name( $cloned_parent_type . ' ' . $cloned_field_name );
83-
$cloned_layout_interface_name = $cloned_layout_interface_prefix . '_Layout';
84-
// wp_send_json( [
85-
// '$parent_type' => $parent_type,
86-
// '$field_name' => $field_name,
87-
// '$acf_field' => $acf_field,
88-
// '$cloned_from' => $cloned_from,
89-
// '$cloned_parent_type' => $cloned_parent_type,
90-
// '$cloned_layout_interface_name' => $cloned_layout_interface_name
91-
// ]);
92-
93-
$interfaces[] = $cloned_layout_interface_name;
94-
}
95-
9676
$layout['eagerlyLoadType'] = true;
9777
$layout['graphql_field_name'] = $layout_name;
9878
$layout['fields'] = [

src/Registry.php

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)