@@ -63,7 +63,7 @@ public function __construct( array $acf_field_groups = [] ) {
6363 * @return void
6464 */
6565 public function set_graphql_type ( string $ field_group_name , string $ graphql_type_name ): void {
66- $ this ->mapped_field_groups [ Utils::format_field_name ( $ field_group_name , true ) ][] = Utils::format_type_name ( $ graphql_type_name );
66+ $ this ->mapped_field_groups [ Utils::format_field_name ( $ field_group_name , true ) ][] = ucfirst ( Utils::format_field_name ( $ graphql_type_name, true ) );
6767 }
6868
6969 /**
@@ -76,7 +76,7 @@ public function set_graphql_type( string $field_group_name, string $graphql_type
7676 * @return void
7777 */
7878 public function unset_graphql_type ( string $ field_group_name , string $ graphql_type_name ): void {
79- $ this ->unset_types [ Utils::format_field_name ( $ field_group_name , true ) ][] = Utils::format_type_name ( $ graphql_type_name );
79+ $ this ->unset_types [ Utils::format_field_name ( $ field_group_name , true ) ][] = ucfirst ( Utils::format_field_name ( $ graphql_type_name, true ) );
8080 }
8181
8282 /**
@@ -323,6 +323,9 @@ public function determine_rules( string $field_group_name, string $param, string
323323 case 'widget ' :
324324 // @todo: Widgets are not currently supported in WPGraphQL
325325 break ;
326+ case 'block ' :
327+ $ this ->determine_block_rules ( $ field_group_name , $ param , $ operator , $ value );
328+ break ;
326329 case 'nav_menu ' :
327330 $ this ->determine_nav_menu_rules ( $ field_group_name , $ param , $ operator , $ value );
328331 break ;
@@ -398,29 +401,11 @@ public function get_graphql_post_template_types(): array {
398401 'default ' => 'DefaultTemplate ' ,
399402 ];
400403
401- $ registered_page_templates = wp_get_theme ()->get_post_templates ();
402-
403- if ( ! empty ( $ registered_page_templates ) && is_array ( $ registered_page_templates ) ) {
404- foreach ( $ registered_page_templates as $ post_type_templates ) {
405- // Post templates are returned as an array of arrays. PHPStan believes they're returned as
406- // an array of strings and believes this will always evaluate to false.
407- // We should ignore the phpstan check here.
408- if ( ! empty ( $ post_type_templates ) && is_array ( $ post_type_templates ) ) {
409- foreach ( $ post_type_templates as $ file => $ name ) {
410- $ name = ucwords ( $ name );
411- $ replaced_name = preg_replace ( '/[^\w]/ ' , '' , $ name );
412-
413- if ( ! empty ( $ replaced_name ) ) {
414- $ name = $ replaced_name ;
415- }
416-
417- if ( preg_match ( '/^\d/ ' , $ name ) || false === strpos ( strtolower ( $ name ), 'template ' ) ) {
418- $ name = 'Template_ ' . $ name ;
419- }
420-
421- $ page_templates [ $ file ] = $ name ;
422- }
423- }
404+ $ allowed_post_types = \WPGraphQL::get_allowed_post_types ();
405+ foreach ( $ allowed_post_types as $ post_type ) {
406+ $ post_type_templates = wp_get_theme ()->get_page_templates ( null , $ post_type );
407+ foreach ( $ post_type_templates as $ file => $ name ) {
408+ $ page_templates [ $ file ] = Utils::format_type_name_for_wp_template ( $ name , $ file );
424409 }
425410 }
426411
@@ -499,16 +484,13 @@ public function determine_post_type_rules( string $field_group_name, string $par
499484 public function determine_post_template_rules ( string $ field_group_name , string $ param , string $ operator , string $ value ): void {
500485 $ templates = $ this ->get_graphql_post_template_types ();
501486
502- if ( ! is_array ( $ templates ) || empty ( $ templates ) ) {
487+ if ( empty ( $ templates ) ) {
503488 return ;
504489 }
505490
506- if ( '== ' === $ operator ) {
507-
508- // If the template is available in GraphQL, set it
509- if ( isset ( $ templates [ $ value ] ) ) {
510- $ this ->set_graphql_type ( $ field_group_name , $ templates [ $ value ] );
511- }
491+ // If the template is available in GraphQL, set it
492+ if ( ( '== ' === $ operator ) && isset ( $ templates [ $ value ] ) ) {
493+ $ this ->set_graphql_type ( $ field_group_name , $ templates [ $ value ] );
512494 }
513495
514496 if ( '!= ' === $ operator ) {
0 commit comments