Skip to content

Commit 8f299a4

Browse files
committed
- modify logic for get_parent_graphql_type_name to account for fields within a flex layout
- remove commented out code from CloneField.php - modify tests to account for multiple field groups being imported in the test suite - update test to account for flex field layout type name change
1 parent b9db850 commit 8f299a4

File tree

4 files changed

+6
-76
lines changed

4 files changed

+6
-76
lines changed

src/FieldConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public function get_graphql_field_type(): ?AcfGraphQLFieldType {
9191
public function get_parent_graphql_type_name( array $acf_field, ?string $prepend = '' ): string {
9292
$type_name = '';
9393

94-
if ( ! empty( $acf_field['parent'] ) ) {
94+
if ( ! empty( $acf_field['parent_layout_group'] ) ) {
95+
$type_name = $this->registry->get_field_group_graphql_type_name( $acf_field['parent_layout_group'] );
96+
} elseif ( ! empty( $acf_field['parent'] ) ) {
9597
$parent_field = acf_get_field( $acf_field['parent'] );
9698
$parent_group = acf_get_field_group( $acf_field['parent'] );
9799
if ( ! empty( $parent_field ) ) {

src/FieldType/CloneField.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static function ( $cloned ) use ( $field_config ) {
4545
);
4646

4747
if ( ! empty( $cloned_group_interfaces ) ) {
48-
4948
if ( ! $prefix_name ) {
5049
register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $parent_type ] );
5150
} else {
@@ -97,79 +96,8 @@ static function ( $cloned ) use ( $field_config ) {
9796
return $type_name;
9897
}
9998
}
100-
10199
// Bail by returning a NULL type
102100
return 'NULL';
103-
104-
105-
106-
107-
//
108-
// $cloned_groups = [];
109-
// if ( ! empty( $sub_field_group['clone'] ) && is_array( $sub_field_group['clone'] ) ) {
110-
// foreach ( $sub_field_group['clone'] as $cloned_from ) {
111-
// if ( ! acf_get_field_group( $cloned_from ) ) {
112-
// continue;
113-
// }
114-
// if ( ! in_array( $cloned_from, $cloned_groups, true ) ) {
115-
// $cloned_groups[] = acf_get_field_group( $cloned_from );
116-
// }
117-
// }
118-
// }
119-
//
120-
// $cloned_group_interfaces = [];
121-
//
122-
// if ( ! empty( $cloned_groups ) ) {
123-
// foreach ( $cloned_groups as $cloned_group ) {
124-
// $cloned_group_interfaces[] = $field_config->get_registry()->get_field_group_graphql_type_name( $cloned_group ) . '_Fields';
125-
// }
126-
// }
127-
//
128-
// if ( ! empty( $cloned_group_interfaces ) ) {
129-
//
130-
// // If a clone field clones all fields from another field group,
131-
// // but has "prefix_name" false, implement the Interface on the parent group
132-
// if ( false === (bool) $sub_field_group['prefix_name'] ) {
133-
// $parent_group = acf_get_field_group( $sub_field_group['parent'] );
134-
//
135-
// if ( empty( $parent_group ) ) {
136-
// $parent_field = acf_get_field( $sub_field_group['parent'] );
137-
// $parent_group = ! empty( $parent_field ) ? acf_get_field_group( $parent_field['parent'] ) : false;
138-
// }
139-
//
140-
// if ( ! empty( $parent_group ) ) {
141-
// $parent_group_type_name = $field_config->get_registry()->get_field_group_graphql_type_name( $parent_group );
142-
//
143-
// if ( isset( $sub_field_group['isFlexLayoutField'] ) && true === (bool) $sub_field_group['isFlexLayoutField'] ) {
144-
// $parent_type_name = $field_config->get_registry()->get_field_group_graphql_type_name( $sub_field_group['parent_layout_group'] ) ?? $type_name;
145-
// register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $parent_type_name ] );
146-
// } else {
147-
// register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $parent_group_type_name ] );
148-
// }
149-
// return 'connection';
150-
// }
151-
// // If "prefix_name" is true, nest the cloned field group within another GraphQL object type to avoid
152-
// // collisions with multiple instances of the field group being cloned
153-
// } else {
154-
// if ( ! empty( $type_name ) ) {
155-
// // Register the cloned group interfaces to the type representing the cloned fields
156-
// register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $type_name ] );
157-
// }
158-
// }
159-
// }
160-
//
161-
//
162-
// $sub_field_group['graphql_type_name'] = $type_name;
163-
// $sub_field_group['graphql_field_name'] = $type_name;
164-
// $sub_field_group['parent'] = $sub_field_group['key'];
165-
//
166-
// $field_config->get_registry()->register_acf_field_groups_to_graphql(
167-
// [
168-
// $sub_field_group,
169-
// ]
170-
// );
171-
//
172-
// return $type_name;
173101
},
174102
// The clone field adds its own settings field to display
175103
'admin_fields' => static function ( $default_admin_settings, $field, $config, \WPGraphQL\Acf\Admin\Settings $settings ) {

tests/functional/AdminSettingsCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function seeCustomFieldsFieldGroupTableTest( FunctionalTester $I ) {
2929
$I->amOnPage('/wp-admin/edit.php?post_type=acf-field-group');
3030

3131
// Grab the first field group name
32-
$I->see( 'Foo Name', "//tbody/tr/td/*/a[@class='row-title']" );
32+
$I->see( 'Foo Name' );
3333

3434
// Grab the wpgraphql type name
35-
$I->assertEquals( 'FooGraphql', $I->grabTextFrom( "//tbody/tr/td/*[@class='acf-wpgraphql-type']" ) );
35+
$I->see( 'FooGraphql' );
3636
}
3737
}

tests/functional/TestCloneFieldsCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ interfaces {
8787
}
8888
',
8989
'variables' => [
90-
'type' => 'AcfProKitchenSinkFlexibleContentLayoutWithClonedGroup'
90+
'type' => 'AcfProKitchenSinkFlexibleContentLayoutWithClonedGroupLayout'
9191
]
9292
]));
9393

0 commit comments

Comments
 (0)