@@ -48,18 +48,8 @@ static function ( $cloned ) use ( $field_config ) {
4848 if ( ! $ prefix_name ) {
4949 register_graphql_interfaces_to_types ( $ cloned_group_interfaces , [ $ parent_type ] );
5050 } else {
51- $ sub_field_group ['graphql_type_name ' ] = $ type_name ;
52- $ sub_field_group ['graphql_field_name ' ] = $ type_name ;
53- $ sub_field_group ['parent ' ] = $ sub_field_group ['key ' ];
54- $ sub_field_group ['sub_fields ' ] = $ cloned_fields ;
55- $ field_config ->get_registry ()->register_acf_field_groups_to_graphql (
56- [
57- $ sub_field_group ,
58- ]
59- );
60-
51+ $ type_name = self ::register_prefixed_clone_field_type ( $ type_name , $ sub_field_group , $ cloned_fields , $ field_config );
6152 register_graphql_interfaces_to_types ( $ cloned_group_interfaces , [ $ type_name ] );
62-
6353 return $ type_name ;
6454 }
6555 }
@@ -83,17 +73,7 @@ static function ( $cloned ) use ( $field_config ) {
8373 // Register a new Object Type with the cloned fields, and return
8474 // the new type.
8575 } else {
86- $ sub_field_group ['graphql_type_name ' ] = $ type_name ;
87- $ sub_field_group ['graphql_field_name ' ] = $ type_name ;
88- $ sub_field_group ['parent ' ] = $ sub_field_group ['key ' ];
89- $ sub_field_group ['sub_fields ' ] = $ cloned_fields ;
90-
91- $ field_config ->get_registry ()->register_acf_field_groups_to_graphql (
92- [
93- $ sub_field_group ,
94- ]
95- );
96- return $ type_name ;
76+ return self ::register_prefixed_clone_field_type ( $ type_name , $ sub_field_group , $ cloned_fields , $ field_config );
9777 }
9878 }
9979 // Bail by returning a NULL type
@@ -115,4 +95,27 @@ static function ( $cloned ) use ( $field_config ) {
11595 ]
11696 );
11797 }
98+
99+ /**
100+ * @param string $type_name The name of the GraphQL Type representing the prefixed clone field
101+ * @param array $sub_field_group The Field Group representing the cloned field
102+ * @param array $cloned_fields The cloned fields to be registered to the Cloned Field Type
103+ * @param \WPGraphQL\Acf\FieldConfig $field_config The ACF Field Config
104+ *
105+ * @return string
106+ * @throws \Exception
107+ */
108+ public static function register_prefixed_clone_field_type ( string $ type_name , array $ sub_field_group , array $ cloned_fields , FieldConfig $ field_config ): string {
109+ $ sub_field_group ['graphql_type_name ' ] = $ type_name ;
110+ $ sub_field_group ['graphql_field_name ' ] = $ type_name ;
111+ $ sub_field_group ['parent ' ] = $ sub_field_group ['key ' ];
112+ $ sub_field_group ['sub_fields ' ] = $ cloned_fields ;
113+
114+ $ field_config ->get_registry ()->register_acf_field_groups_to_graphql (
115+ [
116+ $ sub_field_group ,
117+ ]
118+ );
119+ return $ type_name ;
120+ }
118121}
0 commit comments