Skip to content

Commit 25376f7

Browse files
committed
- refactor get_graphql_locations_for_field_group() to early return for field groups that have graphql_types defined, but still support field groups that don't have graphql_types defined.
1 parent 56f8aa1 commit 25376f7

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Registry.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,33 @@ public function get_graphql_locations_for_field_group( array $field_group, array
568568
return [];
569569
}
570570

571-
$graphql_types = $field_group['graphql_types'] ?? [];
571+
// early return if the field group has graphql_types defined
572+
if ( ! empty( $field_group['graphql_types'] ) && is_array( $field_group['graphql_types'] ) ) {
573+
return array_unique( array_filter( $field_group['graphql_types'] ) );
574+
}
575+
576+
if ( ! isset( $field_group['map_graphql_types_from_location_rules'] ) || false !== (bool) $field_group['map_graphql_types_from_location_rules'] ) {
577+
return [];
578+
}
579+
580+
if ( empty( $field_group['locations'] ) ) {
581+
return [];
582+
}
583+
584+
$field_group_name = \WPGraphQL\Acf\Utils::get_field_group_name( $field_group );
585+
586+
if ( empty( $field_group_name ) ) {
587+
return [];
588+
}
589+
590+
$field_group_name = Utils::format_field_name( $field_group_name, true );
591+
592+
$location_rules = $this->get_location_rules( $acf_field_groups );
593+
if ( isset( $location_rules[ $field_group_name ] ) ) {
594+
$graphql_types = $location_rules[ $field_group_name ];
595+
}
572596

573-
return is_array( $graphql_types ) ? $graphql_types : [ $graphql_types ];
597+
return ! empty( $graphql_types ) && is_array( $graphql_types ) ? array_unique( array_filter( $graphql_types ) ) : [];
574598
}
575599

576600
/**

0 commit comments

Comments
 (0)