Skip to content

Commit 3a22eba

Browse files
committed
- initial exploration of fixing the issue. . .debugging
1 parent b56bef5 commit 3a22eba

File tree

4 files changed

+87
-50
lines changed

4 files changed

+87
-50
lines changed

src/AcfGraphQLFieldType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ 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+
330338
// If the ACF Field is set to "graphql_non_null", map it to the schema as non_null
331339
if ( isset( $acf_field['graphql_non_null'] ) && true === (bool) $acf_field['graphql_non_null'] ) {
332340
$resolve_type = [ 'non_null' => $resolve_type ];

src/FieldType/CloneField.php

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

4+
use WPGraphQL\Acf\AcfGraphQLFieldType;
5+
use WPGraphQL\Acf\FieldConfig;
6+
47
class CloneField {
58

69
/**
@@ -10,7 +13,6 @@ public static function register_field_type():void {
1013
register_graphql_acf_field_type(
1114
'clone',
1215
[
13-
1416
// The clone field adds its own settings field to display
1517
'admin_fields' => static function ( $default_admin_settings, $field, $config, \WPGraphQL\Acf\Admin\Settings $settings ) {
1618

src/FieldType/FlexibleContent.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ 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+
7696
$layout['eagerlyLoadType'] = true;
7797
$layout['graphql_field_name'] = $layout_name;
7898
$layout['fields'] = [

src/Registry.php

Lines changed: 56 additions & 49 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,34 +465,41 @@ 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 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-
}
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+
// }
496503

497504
return $graphql_fields;
498505
}

0 commit comments

Comments
 (0)