From 3ede9a7976506be91ee622406cba7e529b56efa8 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 3 Dec 2019 12:42:52 -0700 Subject: [PATCH] #91 - Don't add flex fields to the Schema if there are no layouts configured --- src/class-config.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/class-config.php b/src/class-config.php index dca8008..530c08a 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -14,7 +14,6 @@ use WPGraphQL\Model\Post; use WPGraphQL\Model\Term; use WPGraphQL\Model\User; -use WPGraphQL\Types; /** * Config class. @@ -777,12 +776,21 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { $flex_field_layout_name = ! empty( $layout['name'] ) ? ucfirst( self::camel_case( $layout['name'] ) ) : null; $flex_field_layout_name = ! empty( $flex_field_layout_name ) ? $field_type_name . '_' . $flex_field_layout_name : null; + + /** + * If there are no layouts defined for the Flex Field + */ + if ( empty( $flex_field_layout_name ) ) { + continue; + } + $layout_type = $this->type_registry->get_type( $flex_field_layout_name ); if ( $layout_type ) { $union_types[ $layout['name'] ] = $layout_type; } else { + register_graphql_object_type( $flex_field_layout_name, [ 'description' => __( 'Group within the flex field', 'wp-graphql-acf' ), 'fields' => [