Skip to content

Commit 09a6168

Browse files
committed
- update Registry to use local Utils and use full namespace for WPGraphQL\Utils\Utils
- normalize location rules to be mapped with strolower
1 parent daf9f74 commit 09a6168

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/LocationRules/LocationRules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct( array $acf_field_groups = [] ) {
6161
* @param string $graphql_type_name The name of the GraphQL Type
6262
*/
6363
public function set_graphql_type( string $field_group_name, string $graphql_type_name ): void {
64-
$this->mapped_field_groups[ Utils::format_field_name( $field_group_name, true ) ][] = ucfirst( Utils::format_field_name( $graphql_type_name, true ) );
64+
$this->mapped_field_groups[ strtolower( Utils::format_field_name( $field_group_name, true ) ) ][] = ucfirst( Utils::format_field_name( $graphql_type_name, true ) );
6565
}
6666

6767
/**

src/Registry.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use WPGraphQL\Acf\Model\AcfOptionsPage;
99
use WPGraphQL\AppContext;
1010
use WPGraphQL\Registry\TypeRegistry;
11-
use WPGraphQL\Utils\Utils;
1211

1312
class Registry {
1413

@@ -95,7 +94,7 @@ public function has_registered_field_group( string $key ): bool {
9594
* @param array<mixed> $acf_field_group
9695
*/
9796
public function should_field_group_show_in_graphql( array $acf_field_group ): bool {
98-
return \WPGraphQL\Acf\Utils::should_field_group_show_in_graphql( $acf_field_group );
97+
return Utils::should_field_group_show_in_graphql( $acf_field_group );
9998
}
10099

101100
/**
@@ -305,7 +304,8 @@ public function get_field_group_interfaces( array $acf_field_group ): array {
305304
* @throws \Exception
306305
*/
307306
public function register_options_pages(): void {
308-
$graphql_options_pages = \WPGraphQL\Acf\Utils::get_acf_options_pages();
307+
308+
$graphql_options_pages = Utils::get_acf_options_pages();
309309

310310
if ( empty( $graphql_options_pages ) ) {
311311
return;
@@ -361,7 +361,7 @@ public function register_options_pages(): void {
361361
]
362362
);
363363

364-
$field_name = Utils::format_field_name( $type_name );
364+
$field_name = \WPGraphQL\Utils\Utils::format_field_name( $type_name );
365365

366366
$interface_name = 'WithAcfOptionsPage' . $type_name;
367367

@@ -507,7 +507,7 @@ public function map_acf_field_to_graphql( array $acf_field, array $acf_field_gro
507507
* @throws \GraphQL\Error\Error
508508
*/
509509
public function get_field_group_name( array $field_group ): string {
510-
return \WPGraphQL\Acf\Utils::get_field_group_name( $field_group );
510+
return Utils::get_field_group_name( $field_group );
511511
}
512512

513513
/**
@@ -516,7 +516,7 @@ public function get_field_group_name( array $field_group ): string {
516516
* @throws \GraphQL\Error\Error
517517
*/
518518
public function get_graphql_field_name( array $acf_field ): string {
519-
return Utils::format_field_name( $this->get_field_group_name( $acf_field ), true );
519+
return \WPGraphQL\Utils\Utils::format_field_name( $this->get_field_group_name( $acf_field ), true );
520520
}
521521

522522
/**
@@ -548,7 +548,7 @@ public function get_field_group_graphql_type_name( array $field_group ): ?string
548548
return null;
549549
}
550550

551-
return Utils::format_type_name( $replaced );
551+
return \WPGraphQL\Utils\Utils::format_type_name( $replaced );
552552
}
553553

554554
/**
@@ -640,9 +640,14 @@ public function get_graphql_locations_for_field_group( array $field_group, array
640640
return $graphql_types;
641641
}
642642

643-
$field_group_name = \WPGraphQL\Acf\Utils::get_field_group_name( $field_group );
643+
$field_group_name = Utils::get_field_group_name( $field_group );
644+
$field_group_name = \WPGraphQL\Utils\Utils::format_field_name( $field_group_name, true );
645+
// The fields are mapped as lowercase strings and should be retrieved as such
646+
// see: LocationRules.php
647+
$field_group_name = strtolower( $field_group_name );
644648

645649
$location_rules = $this->get_location_rules( $acf_field_groups );
650+
646651
if ( isset( $location_rules[ $field_group_name ] ) ) {
647652
$graphql_types = $location_rules[ $field_group_name ];
648653
}
@@ -679,7 +684,7 @@ public function register_acf_field_groups_to_graphql( array $acf_field_groups =
679684
if ( ! empty( $locations ) ) {
680685
$with_field_group_interface_name = 'WithAcf' . $type_name;
681686

682-
$field_name = Utils::format_field_name( $type_name, true );
687+
$field_name = \WPGraphQL\Utils\Utils::format_field_name( $type_name, true );
683688

684689
if ( ! $this->has_registered_field_group( $with_field_group_interface_name ) ) {
685690
register_graphql_interface_type(

tests/_support/WPUnit/WPGraphQLAcfTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ public function register_acf_field_group( array $acf_field_group = [] ) {
294294
* @return string
295295
*/
296296
public function register_acf_field( array $acf_field = [], array $acf_field_group = [] ): string {
297-
298-
299297
$field_group_key = $this->register_acf_field_group( $acf_field_group );
300298

301299
$key = $acf_field['key'] ?? uniqid( 'field_acf_test_',true );

0 commit comments

Comments
 (0)