From ccefe2946e59bcb94da0dfb23e4388dd4f1f855c Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 27 Apr 2020 08:26:19 -0600 Subject: [PATCH 01/17] - Update version number for release --- wp-graphql-acf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-graphql-acf.php b/wp-graphql-acf.php index 697c14c..9597d36 100644 --- a/wp-graphql-acf.php +++ b/wp-graphql-acf.php @@ -7,7 +7,7 @@ * Author URI: https://www.wpgraphql.com * Text Domain: wp-graphql-acf * Domain Path: /languages - * Version: 0.3.2 + * Version: 0.3.3 * Requires PHP: 7.0 * GitHub Plugin URI: https://github.com/afragen/github-updater * From 89f3adb76011859284d2418f51dfefe557b0d87a Mon Sep 17 00:00:00 2001 From: Twansparant Date: Thu, 14 May 2020 09:03:28 +0200 Subject: [PATCH 02/17] Fixes #76 --- src/class-config.php | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/class-config.php b/src/class-config.php index 91d2dc6..0bd4d08 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -48,6 +48,7 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { $this->add_acf_fields_to_individual_posts(); $this->add_acf_fields_to_users(); $this->add_acf_fields_to_options_pages(); + $this->add_acf_fields_to_pages(); } /** @@ -1728,4 +1729,100 @@ protected function add_acf_fields_to_options_pages() { } } + /** + * Add field groups for `page_type` and `page_template`. + * Note that these will show up for all pages in the schema, + * they will not be limited to the page types or templates assigned in the field group. + */ + protected function add_acf_fields_to_pages() { + + $page_field_groups = []; + + /** + * Get the field groups. + * + * TODO: Can we filter this to only page related ACF Field Groups? + */ + $field_groups = acf_get_field_groups(); + + /** + * We only want to add field groups for page type and template params. + * Page by location is already covered by `add_acf_fields_to_individual_posts`, + * so we do not want to duplicate that. + */ + $allowed_page_params = [ + 'page_type', + 'page_template', + ]; + + foreach ( $field_groups as $field_group ) { + if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { + foreach ( $field_group['location'] as $locations ) { + if ( ! empty( $locations ) && is_array( $locations ) ) { + foreach ( $locations as $location ) { + + /** + * If the operator is not equal to, we don't need to do anything, + * so we can just continue + */ + if ( '!=' === $location['operator'] ) { + continue; + } + + /** + * Add field group if the param is page related. + */ + if ( in_array( $location['param'], $allowed_page_params, true ) && '==' === $location['operator'] ) { + $page_field_groups[] = [ + 'type' => $location['param'], + 'field_group' => $field_group, + 'post_id' => $location['value'] + ]; + } + } + } + } + } + } + + + /** + * If no field groups are assigned to pages, we don't need to modify the Schema. + */ + if ( empty( $page_field_groups ) ) { + return; + } + + /** + * Loop over the field groups assigned to pages + * and register them to the Schema + */ + foreach ( $page_field_groups as $key => $group ) { + + if ( empty( $group['field_group'] ) || ! is_array( $group['field_group'] ) ) { + continue; + } + + // Initialize our field group object. + $field_group = $group['field_group']; + + $page_type_object = get_post_type_object('page'); + + $field_name = isset( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : Config::camel_case( $field_group['title'] ); + $field_group['type'] = 'group'; + $field_group['name'] = $field_name; + $description = $field_group['description'] ? $field_group['description'] . ' | ' : ''; + $config = [ + 'name' => $field_name, + 'description' => $description, + 'acf_field' => $field_group, + 'acf_field_group' => null, + 'resolve' => function( $root ) use ( $field_group ) { + return isset( $root ) ? $root : null; + } + ]; + + $this->register_graphql_field($page_type_object->graphql_single_name, $field_name, $config); + } + } } From 3c4bd38cb415bd1326fd1ec83a44698329340823 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Fri, 15 May 2020 17:41:08 +0200 Subject: [PATCH 03/17] Start adding gravityforms add-on support --- src/class-config.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/class-config.php b/src/class-config.php index 0bd4d08..3a2cfc3 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -333,7 +333,8 @@ public static function get_supported_fields() { 'color_picker', 'group', 'repeater', - 'flexible_content' + 'flexible_content', + 'forms' ]; /** @@ -1020,6 +1021,37 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { }; } break; + case 'forms': + /** + * If the select field is configured to not allow multiple values + * the field will return a string, but if it is configured to allow + * multiple values it will return a list of strings, and an empty array + * if no values are set. + * + * @see: https://github.com/wp-graphql/wp-graphql-acf/issues/25 + */ + if ( empty( $acf_field['multiple'] ) ) { + if ($acf_field['return_format'] === 'post_object') { + //$field_config['type'] = 'PostObject'; + $field_config['type'] = 'Integer'; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $value = $this->get_acf_field_value( $root, $acf_field ); + $gform = GFAPI::get_form($value); + + return ! empty( $value ) ? $value : null; + }; + } else { + $field_config['type'] = 'Integer'; + } + } else { + $field_config['type'] = [ 'list_of' => 'String' ]; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $value = $this->get_acf_field_value( $root, $acf_field ); + + return ! empty( $value ) && is_array( $value ) ? $value : []; + }; + } + break; default: break; } From 581f1b1eedead0f060accda7109a957057420790 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Fri, 15 May 2020 20:30:28 +0200 Subject: [PATCH 04/17] Add GravityForm object type --- src/class-config.php | 48 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 3a2cfc3..e169b9c 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -1021,7 +1021,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { }; } break; - case 'forms': + case 'forms' && class_exists( 'ACFGravityformsField\\Init' ) : /** * If the select field is configured to not allow multiple values * the field will return a string, but if it is configured to allow @@ -1032,13 +1032,51 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { */ if ( empty( $acf_field['multiple'] ) ) { if ($acf_field['return_format'] === 'post_object') { - //$field_config['type'] = 'PostObject'; - $field_config['type'] = 'Integer'; + + $field_type_name = 'GravityForm'; + if ( $this->type_registry->get_type( $field_type_name ) == $field_type_name ) { + $field_config['type'] = $field_type_name; + break; + } + + register_graphql_object_type( + $field_type_name, + [ + 'description' => __( 'Gravity Form Object', 'wp-graphql-acf' ), + 'fields' => [ + 'id' => [ + 'type' => 'Integer', + 'description' => __( 'The id of the Gravity Form', 'wp-graphql-acf' ), + ], + 'title' => [ + 'type' => 'String', + 'description' => __( 'The title of the Gravity Form', 'wp-graphql-acf' ), + ], + 'description' => [ + 'type' => 'String', + 'description' => __( 'The description of the Gravity Form', 'wp-graphql-acf' ), + ], + 'labelPlacement' => [ + 'type' => 'String', + 'description' => __( 'The label placement of the Gravity Form', 'wp-graphql-acf' ), + ], + 'descriptionPlacement' => [ + 'type' => 'String', + 'description' => __( 'The description placement of the Gravity Form', 'wp-graphql-acf' ), + ], + 'fields' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'The fields of the Gravity Form', 'wp-graphql-acf' ), + ] + ], + ] + ); + $field_config['type'] = $field_type_name; $field_config['resolve'] = function( $root ) use ( $acf_field ) { $value = $this->get_acf_field_value( $root, $acf_field ); - $gform = GFAPI::get_form($value); + $gform = class_exists( 'GFAPI' ) ? \GFAPI::get_form($value) : null; - return ! empty( $value ) ? $value : null; + return ! empty( $gform ) ? $gform : null; }; } else { $field_config['type'] = 'Integer'; From 187d4b3baac6bcdf219a7a28c0cd84c474ee65d6 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 09:42:29 +0200 Subject: [PATCH 05/17] Add gravity form object fields --- src/class-config.php | 234 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 201 insertions(+), 33 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index e169b9c..41dcef0 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -814,79 +814,79 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { // ACF 5.8.6 added more data to Google Maps field value // https://www.advancedcustomfields.com/changelog/ if (\acf_version_compare(acf_get_db_version(), '>=', '5.8.6')) { - $fields += [ - 'streetName' => [ + $fields += [ + 'streetName' => [ 'type' => 'String', 'description' => __( 'The street name associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['street_name'] ) ? $root['street_name'] : null; }, - ], - 'streetNumber' => [ + ], + 'streetNumber' => [ 'type' => 'String', 'description' => __( 'The street number associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['street_number'] ) ? $root['street_number'] : null; }, - ], - 'city' => [ + ], + 'city' => [ 'type' => 'String', 'description' => __( 'The city associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['city'] ) ? $root['city'] : null; }, - ], - 'state' => [ + ], + 'state' => [ 'type' => 'String', 'description' => __( 'The state associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['state'] ) ? $root['state'] : null; }, - ], - 'stateShort' => [ + ], + 'stateShort' => [ 'type' => 'String', 'description' => __( 'The state abbreviation associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['state_short'] ) ? $root['state_short'] : null; }, - ], - 'postCode' => [ + ], + 'postCode' => [ 'type' => 'String', 'description' => __( 'The post code associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['post_code'] ) ? $root['post_code'] : null; }, - ], - 'country' => [ + ], + 'country' => [ 'type' => 'String', 'description' => __( 'The country associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['country'] ) ? $root['country'] : null; }, - ], - 'countryShort' => [ + ], + 'countryShort' => [ 'type' => 'String', 'description' => __( 'The country abbreviation associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['country_short'] ) ? $root['country_short'] : null; }, - ], - 'placeId' => [ + ], + 'placeId' => [ 'type' => 'String', 'description' => __( 'The country associated with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['place_id'] ) ? $root['place_id'] : null; }, - ], - 'zoom' => [ + ], + 'zoom' => [ 'type' => 'String', 'description' => __( 'The zoom defined with the map', 'wp-graphql-acf' ), 'resolve' => function( $root ) { return isset( $root['zoom'] ) ? $root['zoom'] : null; }, - ], - ]; - } + ], + ]; + } register_graphql_object_type( $field_type_name, @@ -1045,29 +1045,197 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'description' => __( 'Gravity Form Object', 'wp-graphql-acf' ), 'fields' => [ 'id' => [ - 'type' => 'Integer', - 'description' => __( 'The id of the Gravity Form', 'wp-graphql-acf' ), + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( 'Unique global ID for the object.', 'wp-graphql-acf' ), + ], + 'formId' => [ + 'type' => 'Int', + 'description' => __( 'Form ID.', 'wp-graphql-acf' ), ], - 'title' => [ + 'title' => [ 'type' => 'String', - 'description' => __( 'The title of the Gravity Form', 'wp-graphql-acf' ), + 'description' => __( 'Form title.', 'wp-graphql-acf' ), ], 'description' => [ 'type' => 'String', - 'description' => __( 'The description of the Gravity Form', 'wp-graphql-acf' ), + 'description' => __( 'Form description.', 'wp-graphql-acf' ), ], 'labelPlacement' => [ 'type' => 'String', - 'description' => __( 'The label placement of the Gravity Form', 'wp-graphql-acf' ), + 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-acf' ), ], 'descriptionPlacement' => [ 'type' => 'String', - 'description' => __( 'The description placement of the Gravity Form', 'wp-graphql-acf' ), + 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), + ], + 'button' => [ + 'type' => Button::TYPE, + 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), + ], + 'useCurrentUserAsAuthor' => [ + 'type' => 'Boolean', + 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-acf' ), + ], + 'postAuthor' => [ + 'type' => 'Int', + 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-acf' ), + ], + 'postCategory' => [ + 'type' => 'Int', + 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-acf' ), + ], + 'postContentTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-acf' ), + ], + 'postContentTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-acf' ), + ], + 'postFormat' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-acf' ), + ], + 'postStatus' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-acf' ), + ], + 'postTitleTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-acf' ), + ], + 'postTitleTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), + ], + 'lastPageButton' => [ + 'type' => Button::TYPE, + 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), + ], + 'pagination' => [ + 'type' => FormPagination::TYPE, + 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), + ], + 'firstPageCssClass' => [ + 'type' => 'String', + 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), + ], + 'notifications' => [ + 'type' => [ 'list_of' => FormNotification::TYPE ], + 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), + ], + 'confirmations' => [ + 'type' => [ 'list_of' => FormConfirmation::TYPE ], + 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), + ], + 'cssClass' => [ + 'type' => 'String', + 'description' => __( 'String containing the custom CSS classes to be added to the
tag.', 'wp-graphql-acf' ), + ], + 'enableHoneypot' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-acf' ), + ], + 'enableAnimation' => [ + 'type' => 'Boolean', + 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), ], - 'fields' => [ + 'save' => [ + 'type' => SaveAndContinue::TYPE, + 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), + ], + 'limitEntries' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), + ], + 'limitEntriesCount' => [ + 'type' => 'Int', + 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-acf' ), + ], + 'limitEntriesPeriod' => [ + 'type' => 'String', + 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-acf' ), + ], + 'limitEntriesMessage' => [ + 'type' => 'String', + 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-acf' ), + ], + 'scheduleForm' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-acf' ), + ], + 'scheduleStart' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartAmpm' => [ + 'type' => 'String', + 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-acf' ), + ], + 'scheduleEnd' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndAmpm' => [ + 'type' => 'String', + 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-acf' ), + ], + 'scheduleMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-acf' ), + ], + 'schedulePendingMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-acf' ), + ], + 'subLabelPlacement' => [ + 'type' => 'String', + 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-acf' ), + ], + 'cssClassList' => [ 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'The fields of the Gravity Form', 'wp-graphql-acf' ), - ] + 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), + ], + 'requireLogin' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-acf' ), + ], + 'requireLoginMessage' => [ + 'type' => 'String', + 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-acf' ), + ], + 'nextFieldId' => [ + 'type' => 'Int', + 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-acf' ), + ], + 'isActive' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is active.', 'wp-graphql-acf' ), + ], + 'dateCreated' => [ + 'type' => 'String', + 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-acf' ), + ], + 'isTrash' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-acf' ), + ], ], ] ); From 6a3b0fd0b76bb3754c5a43c4f194a4388f174b4a Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 09:52:55 +0200 Subject: [PATCH 06/17] Add button types --- src/class-config.php | 60 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 41dcef0..ba2c85b 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -1069,7 +1069,25 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), ], 'button' => [ - 'type' => Button::TYPE, + 'type' => [ 'list_of' => [ + 'type' => [ + 'type' => 'String', + 'description' => __( 'Specifies the type of button to be displayed. Possible values: text, image.', 'wp-graphql-gravity-forms' ), + ], + 'text' => [ + 'type' => 'String', + 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), + ], + 'imageUrl' => [ + 'type' => 'String', + 'description' => __( 'Contains the URL for the image button. Only applicable when type is set to image.', 'wp-graphql-gravity-forms' ), + ], + // 'conditionalLogic' => [ + // 'type' => ConditionalLogic::TYPE, + // 'description' => __( 'Controls when the form button should be visible based on values selected on the form.', 'wp-graphql-gravity-forms' ), + // ], + ] + ], 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), ], 'useCurrentUserAsAuthor' => [ @@ -1108,26 +1126,26 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'type' => 'Boolean', 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), ], - 'lastPageButton' => [ - 'type' => Button::TYPE, - 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), - ], - 'pagination' => [ - 'type' => FormPagination::TYPE, - 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), - ], + // 'lastPageButton' => [ + // 'type' => Button::TYPE, + // 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), + // ], + // 'pagination' => [ + // 'type' => FormPagination::TYPE, + // 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), + // ], 'firstPageCssClass' => [ 'type' => 'String', 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), ], - 'notifications' => [ - 'type' => [ 'list_of' => FormNotification::TYPE ], - 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), - ], - 'confirmations' => [ - 'type' => [ 'list_of' => FormConfirmation::TYPE ], - 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), - ], + // 'notifications' => [ + // 'type' => [ 'list_of' => FormNotification::TYPE ], + // 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), + // ], + // 'confirmations' => [ + // 'type' => [ 'list_of' => FormConfirmation::TYPE ], + // 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), + // ], 'cssClass' => [ 'type' => 'String', 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), @@ -1140,10 +1158,10 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'type' => 'Boolean', 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), ], - 'save' => [ - 'type' => SaveAndContinue::TYPE, - 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), - ], + // 'save' => [ + // 'type' => SaveAndContinue::TYPE, + // 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), + // ], 'limitEntries' => [ 'type' => 'Boolean', 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), From 5369793cb88bda9ba231be131c386eb518e1d085 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 10:18:16 +0200 Subject: [PATCH 07/17] Add WPGraphQLGravityForms class --- src/class-config.php | 62 ++-- .../Types/Button/Button.php | 45 +++ .../ConditionalLogic/ConditionalLogic.php | 41 +++ .../ConditionalLogic/ConditionalLogicRule.php | 40 +++ .../Types/Entry/Entry.php | 181 +++++++++++ .../Types/Entry/EntryForm.php | 74 +++++ .../Types/Entry/EntryUser.php | 64 ++++ .../Enum/FieldFiltersOperatorInputEnum.php | 52 ++++ .../Types/Enum/FormStatusEnum.php | 47 +++ .../Types/Field/AddressField.php | 66 ++++ .../Types/Field/CalculationField.php | 56 ++++ .../Types/Field/CaptchaField.php | 67 ++++ .../Types/Field/ChainedSelectField.php | 56 ++++ .../Types/Field/CheckboxField.php | 52 ++++ .../Types/Field/DateField.php | 63 ++++ .../Types/Field/EmailField.php | 43 +++ .../Types/Field/Field.php | 69 +++++ .../ChainedSelectChoiceProperty.php | 44 +++ .../FieldProperty/CheckboxInputProperty.php | 40 +++ .../Field/FieldProperty/ChoiceProperty.php | 42 +++ .../Field/FieldProperty/ChoicesProperty.php | 26 ++ .../FieldProperty/DefaultValueProperty.php | 22 ++ .../DescriptionPlacementProperty.php | 21 ++ .../FieldProperty/DescriptionProperty.php | 19 ++ .../EnableChoiceValueProperty.php | 21 ++ .../EnableEnhancedUiProperty.php | 26 ++ .../FieldProperty/ErrorMessageProperty.php | 21 ++ .../Field/FieldProperty/InputNameProperty.php | 21 ++ .../Field/FieldProperty/InputProperty.php | 48 +++ .../Field/FieldProperty/InputsProperty.php | 21 ++ .../FieldProperty/IsRequiredProperty.php | 21 ++ .../FieldProperty/LabelPlacementProperty.php | 20 ++ .../FieldProperty/ListChoiceProperty.php | 38 +++ .../Field/FieldProperty/MaxLengthProperty.php | 23 ++ .../MultiSelectChoiceProperty.php | 42 +++ .../FieldProperty/NoDuplicatesProperty.php | 22 ++ .../FieldProperty/PasswordInputProperty.php | 46 +++ .../FieldProperty/PlaceholderProperty.php | 19 ++ .../Field/FieldProperty/SizeProperty.php | 23 ++ .../Field/FieldValue/AddressFieldValue.php | 74 +++++ .../FieldValue/ChainedSelectFieldValue.php | 51 ++++ .../Field/FieldValue/CheckboxFieldValue.php | 59 ++++ .../Types/Field/FieldValue/DateFieldValue.php | 49 +++ .../Field/FieldValue/EmailFieldValue.php | 49 +++ .../Field/FieldValue/FileUploadFieldValue.php | 49 +++ .../FieldValue/MultiSelectFieldValue.php | 49 +++ .../Types/Field/FieldValue/NameFieldValue.php | 69 +++++ .../Field/FieldValue/NumberFieldValue.php | 49 +++ .../Field/FieldValue/PhoneFieldValue.php | 49 +++ .../Field/FieldValue/RadioFieldValue.php | 49 +++ .../Field/FieldValue/SelectFieldValue.php | 49 +++ .../Field/FieldValue/SignatureFieldValue.php | 53 ++++ .../Field/FieldValue/TextAreaFieldValue.php | 49 +++ .../Types/Field/FieldValue/TextFieldValue.php | 49 +++ .../Types/Field/FieldValue/TimeFieldValue.php | 71 +++++ .../Field/FieldValue/WebsiteFieldValue.php | 49 +++ .../Types/Field/FileUploadField.php | 40 +++ .../Types/Field/HiddenField.php | 40 +++ .../Types/Field/HtmlField.php | 42 +++ .../Types/Field/ListField.php | 67 ++++ .../Types/Field/MultiSelectField.php | 49 +++ .../Types/Field/NameField.php | 51 ++++ .../Types/Field/NumberField.php | 60 ++++ .../Types/Field/PageField.php | 53 ++++ .../Types/Field/PasswordField.php | 55 ++++ .../Types/Field/PhoneField.php | 52 ++++ .../Types/Field/PostCategoryField.php | 47 +++ .../Types/Field/PostContentField.php | 42 +++ .../Types/Field/PostCustomField.php | 53 ++++ .../Types/Field/PostExcerptField.php | 42 +++ .../Types/Field/PostImageField.php | 54 ++++ .../Types/Field/PostTagsField.php | 42 +++ .../Types/Field/PostTitleField.php | 42 +++ .../Types/Field/RadioField.php | 49 +++ .../Types/Field/SectionField.php | 34 +++ .../Types/Field/SelectField.php | 45 +++ .../Types/Field/SignatureField.php | 71 +++++ .../Types/Field/TextAreaField.php | 44 +++ .../Types/Field/TextField.php | 50 +++ .../Types/Field/TimeField.php | 42 +++ .../Types/Field/WebsiteField.php | 43 +++ .../Types/FieldError/FieldError.php | 29 ++ .../WPGraphQLGravityForms/Types/Form/Form.php | 285 ++++++++++++++++++ .../Types/Form/FormConfirmation.php | 59 ++++ .../Types/Form/FormNotification.php | 96 ++++++ .../Types/Form/FormNotificationRouting.php | 44 +++ .../Types/Form/FormPagination.php | 57 ++++ .../Types/Form/SaveAndContinue.php | 34 +++ .../Types/Input/CheckboxInput.php | 36 +++ .../Types/Input/EntriesDateFiltersInput.php | 36 +++ .../Types/Input/EntriesFieldFiltersInput.php | 54 ++++ .../Types/Input/EntriesSortingInput.php | 41 +++ .../Types/Union/ObjectFieldUnion.php | 78 +++++ .../Types/Union/ObjectFieldValueUnion.php | 80 +++++ 94 files changed, 4719 insertions(+), 39 deletions(-) create mode 100644 src/classes/WPGraphQLGravityForms/Types/Button/Button.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/DateField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/Field.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/ListField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/NameField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PageField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TextField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/Form.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php create mode 100644 src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php diff --git a/src/class-config.php b/src/class-config.php index ba2c85b..ca7d79d 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -16,6 +16,8 @@ use WPGraphQL\Model\Post; use WPGraphQL\Model\Term; use WPGraphQL\Model\User; +use WPGraphQLGravityForms\Types\Union\ObjectFieldUnion; +use WPGraphQLGravityForms\Types\Button\Button; /** * Config class. @@ -1069,25 +1071,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), ], 'button' => [ - 'type' => [ 'list_of' => [ - 'type' => [ - 'type' => 'String', - 'description' => __( 'Specifies the type of button to be displayed. Possible values: text, image.', 'wp-graphql-gravity-forms' ), - ], - 'text' => [ - 'type' => 'String', - 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), - ], - 'imageUrl' => [ - 'type' => 'String', - 'description' => __( 'Contains the URL for the image button. Only applicable when type is set to image.', 'wp-graphql-gravity-forms' ), - ], - // 'conditionalLogic' => [ - // 'type' => ConditionalLogic::TYPE, - // 'description' => __( 'Controls when the form button should be visible based on values selected on the form.', 'wp-graphql-gravity-forms' ), - // ], - ] - ], + 'type' => Button::TYPE, 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), ], 'useCurrentUserAsAuthor' => [ @@ -1126,26 +1110,26 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'type' => 'Boolean', 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), ], - // 'lastPageButton' => [ - // 'type' => Button::TYPE, - // 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), - // ], - // 'pagination' => [ - // 'type' => FormPagination::TYPE, - // 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), - // ], + 'lastPageButton' => [ + 'type' => Button::TYPE, + 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), + ], + 'pagination' => [ + 'type' => FormPagination::TYPE, + 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), + ], 'firstPageCssClass' => [ 'type' => 'String', 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), ], - // 'notifications' => [ - // 'type' => [ 'list_of' => FormNotification::TYPE ], - // 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), - // ], - // 'confirmations' => [ - // 'type' => [ 'list_of' => FormConfirmation::TYPE ], - // 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), - // ], + 'notifications' => [ + 'type' => [ 'list_of' => FormNotification::TYPE ], + 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), + ], + 'confirmations' => [ + 'type' => [ 'list_of' => FormConfirmation::TYPE ], + 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), + ], 'cssClass' => [ 'type' => 'String', 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), @@ -1158,10 +1142,10 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { 'type' => 'Boolean', 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), ], - // 'save' => [ - // 'type' => SaveAndContinue::TYPE, - // 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), - // ], + 'save' => [ + 'type' => SaveAndContinue::TYPE, + 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), + ], 'limitEntries' => [ 'type' => 'Boolean', 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), diff --git a/src/classes/WPGraphQLGravityForms/Types/Button/Button.php b/src/classes/WPGraphQLGravityForms/Types/Button/Button.php new file mode 100644 index 0000000..4b4dc22 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Button/Button.php @@ -0,0 +1,45 @@ + __( 'Gravity Forms button.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + // @TODO: Convert to an enum. + 'type' => [ + 'type' => 'String', + 'description' => __( 'Specifies the type of button to be displayed. Possible values: text, image.', 'wp-graphql-gravity-forms' ), + ], + 'text' => [ + 'type' => 'String', + 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), + ], + 'imageUrl' => [ + 'type' => 'String', + 'description' => __( 'Contains the URL for the image button. Only applicable when type is set to image.', 'wp-graphql-gravity-forms' ), + ], + 'conditionalLogic' => [ + 'type' => ConditionalLogic::TYPE, + 'description' => __( 'Controls when the form button should be visible based on values selected on the form.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php new file mode 100644 index 0000000..f152849 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php @@ -0,0 +1,41 @@ + __( 'Gravity Forms conditional logic.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + // TODO: convert type to enum + 'actionType' => [ + 'type' => 'String', + 'description' => __( 'The type of action the conditional logic will perform. Possible values: show, hide.', 'wp-graphql-gravity-forms' ), + ], + // TODO: convert type to enum + 'logicType' => [ + 'type' => 'String', + 'description' => __( 'Determines how to the rules should be evaluated. Possible values: any, all.', 'wp-graphql-gravity-forms' ), + ], + 'rules' => [ + 'type' => [ 'list_of' => ConditionalLogicRule::TYPE ], + 'description' => __( 'Conditional logic rules.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php new file mode 100644 index 0000000..594c7f3 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php @@ -0,0 +1,40 @@ + __( 'Gravity Forms conditional logic rule.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'fieldId' => [ + 'type' => 'Integer', + 'description' => __( 'Target field Id. Field that will have it’s value compared with the value property to determine if this rule is a match.', 'wp-graphql-gravity-forms' ), + ], + // TODO: convert to enum. + 'operator' => [ + 'type' => 'String', + 'description' => __( 'Operator to be used when evaluating this rule. Possible values: is, isnot, >, <, contains, starts_with, or ends_with.', 'wp-graphql-gravity-forms' ), + ], + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value to compare with field specified by fieldId.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php b/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php new file mode 100644 index 0000000..0663a89 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php @@ -0,0 +1,181 @@ +entry_data_manipulator = $entry_data_manipulator; + $this->draft_entry_data_manipulator = $draft_entry_data_manipulator; + } + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register_type' ] ); + add_action( 'graphql_register_types', [ $this, 'register_field' ] ); + } + + public function register_type() { + register_graphql_object_type( self::TYPE, [ + 'description' => __( 'Gravity Forms entry.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( 'Unique global ID for the object.', 'wp-graphql-gravity-forms' ), + ], + 'entryId' => [ + 'type' => 'Integer', + 'description' => __( 'The entry ID. Returns null for draft entries.', 'wp-graphql-gravity-forms' ), + ], + 'formId' => [ + 'type' => 'Integer', + 'description' => __( 'The ID of the form that was submitted to generate this entry.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Add field to get post data. + 'postId' => [ + 'type' => 'Integer', + 'description' => __( 'For forms with Post fields, this property contains the Id of the Post that was created.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Gravity Forms stores and returns the dateCreated and dateUpdated in UTC time. + // Change the fields below to be in the blog's local time, and add new ones for + // dateCreatedUTC and dateUpdatedUTC. + 'dateCreated' => [ + 'type' => 'String', + 'description' => __( 'The date and time that the entry was created, in the format "yyyy-mm-dd hh:mi:ss" (i.e. 2010-07-15 17:26:58).', 'wp-graphql-gravity-forms' ), + ], + 'dateUpdated' => [ + 'type' => 'String', + 'description' => __( 'The date and time that the entry was updated, in the format "yyyy-mm-dd hh:mi:ss" (i.e. 2010-07-15 17:26:58).', 'wp-graphql-gravity-forms' ), + ], + 'isStarred' => [ + 'type' => 'Boolean', + 'description' => __( 'Indicates if the entry has been starred (i.e marked with a star). 1 for entries that are starred and 0 for entries that are not starred.', 'wp-graphql-gravity-forms' ), + ], + 'isRead' => [ + 'type' => 'Boolean', + 'description' => __( 'Indicates if the entry has been read. 1 for entries that are read and 0 for entries that have not been read.', 'wp-graphql-gravity-forms' ), + ], + 'ip' => [ + 'type' => 'String', + 'description' => __( 'Client IP of user who submitted the form.', 'wp-graphql-gravity-forms' ), + ], + 'sourceUrl' => [ + 'type' => 'String', + 'description' => __( 'Source URL of page that contained the form when it was submitted.', 'wp-graphql-gravity-forms' ), + ], + 'userAgent' => [ + 'type' => 'String', + 'description' => __( 'Provides the name and version of both the browser and operating system from which the entry was submitted.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Add field to get user data. + 'createdById' => [ + 'type' => 'Integer', + 'description' => __( 'ID of the user that submitted of the form if a logged in user submitted the form.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to an enum. + 'status' => [ + 'type' => 'String', + 'description' => __( 'The current status of the entry; "active", "spam", or "trash".', 'wp-graphql-gravity-forms' ), + ], + 'isDraft' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the entry is a draft.', 'wp-graphql-gravity-forms' ), + ], + 'resumeToken' => [ + 'type' => 'String', + 'description' => __( 'The resume token. Only applies to draft entries.', 'wp-graphql-gravity-forms' ), + ], + /** + * @TODO: Add support for these pricing properties that are only relevant + * when a Gravity Forms payment gateway add-on is being used: + * https://docs.gravityforms.com/entry-object/#pricing-properties + */ + ], + ] ); + } + + public function register_field() { + register_graphql_field( 'RootQuery', self::FIELD, [ + 'description' => __( 'Get a Gravity Forms entry.', 'wp-graphql-gravity-forms' ), + 'type' => self::TYPE, + 'args' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( "Unique global ID for the object. Base-64 encode a string like this, where '123' is the entry ID (or the resume token for a draft entry): '{self::TYPE}:123'.", 'wp-graphql-gravity-forms' ), + ], + ], + 'resolve' => function( $root, array $args, AppContext $context, ResolveInfo $info ) { + if ( ! current_user_can( 'gravityforms_view_entries' ) ) { + throw new UserError( __( 'Sorry, you are not allowed to view Gravity Forms entries.', 'wp-graphql-gravity-forms' ) ); + } + + $id_parts = Relay::fromGlobalId( $args['id'] ); + + if ( ! is_array( $id_parts ) || empty( $id_parts['id'] ) || empty( $id_parts['type'] ) ) { + throw new UserError( __( 'A valid global ID must be provided.', 'wp-graphql-gravity-forms' ) ); + } + + $id = sanitize_text_field( $id_parts['id'] ); + $entry = GFAPI::get_entry( $id ); + + if ( ! is_wp_error( $entry ) ) { + return $this->entry_data_manipulator->manipulate( $entry ); + } + + $draft_entry = GFFormsModel::get_draft_submission_values( $id ); + + if ( ! $draft_entry || ! is_array( $draft_entry ) ) { + throw new UserError( __( 'An entry with this ID was not found.', 'wp-graphql-gravity-forms' ) ); + } + + $submission = json_decode( $draft_entry['submission'], true ); + + if ( ! $submission ) { + throw new UserError( __( 'The submission data for this draft entry could not be read.', 'wp-graphql-gravity-forms' ) ); + } + + return $this->draft_entry_data_manipulator->manipulate( $submission['partial_entry'], $id ); + } + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php new file mode 100644 index 0000000..ebe47d6 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php @@ -0,0 +1,74 @@ +form_data_manipulator = $form_data_manipulator; + } + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register_type' ] ); + add_action( 'graphql_register_types', [ $this, 'register_field' ] ); + } + + /** + * Register new edge type. + */ + public function register_type() { + register_graphql_type( self::TYPE, [ + 'description' => __('The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'node' => [ + 'type' => Form::TYPE, + 'description' => __( 'The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + public function register_field() { + register_graphql_field( Entry::TYPE, self::FIELD, [ + 'type' => self::TYPE, + 'description' => __( 'The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms' ), + 'resolve' => function( array $entry ) : array { + $form = GFAPI::get_form( $entry['formId'] ); + + if ( ! $form ) { + throw new UserError( __( 'The form used to generate this entry was not found.', 'wp-graphql-gravity-forms' ) ); + } + + return [ + 'node' => $this->form_data_manipulator->manipulate( $form ), + ]; + } + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php new file mode 100644 index 0000000..b06b764 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php @@ -0,0 +1,64 @@ + __('The user who created the entry.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'node' => [ + 'type' => 'User', + 'description' => __( 'The user who created the entry.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + public function register_field() { + register_graphql_field( Entry::TYPE, self::FIELD, [ + 'type' => self::TYPE, + 'description' => __( 'The user who created the entry.', 'wp-graphql-gravity-forms' ), + 'resolve' => function( array $entry ) : array { + $user = get_userdata( $entry['createdById'] ); + + if ( ! $user instanceof WP_User ) { + throw new UserError( __( 'The user who created this entry could not be found.', 'wp-graphql-gravity-forms' ) ); + } + + return [ + 'node' => new User( $user ), + ]; + } + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php b/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php new file mode 100644 index 0000000..77ef421 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php @@ -0,0 +1,52 @@ +'; + const LESS_THAN = '<'; + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register' ] ); + } + + public function register() { + register_graphql_enum_type( + self::TYPE, + [ + 'description' => __( 'The operator to use for filtering.', 'harness' ), + 'values' => [ + 'IN' => [ + 'description' => __( 'Find field values that match those in the values array (default).', 'harness' ), + 'value' => self::IN, + ], + 'NOT_IN' => [ + 'description' => __( 'Find field values that do NOT match those in the values array.', 'harness' ), + 'value' => self::NOT_IN, + ], + 'CONTAINS' => [ + 'description' => __( 'Find field values that contain the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), + 'value' => self::CONTAINS, + ], + 'GREATER_THAN' => [ + 'description' => __( 'Find field values that are greater than the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), + 'value' => self::GREATER_THAN, + ], + 'LESS_THAN' => [ + 'description' => __( 'Find field values that are less than the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), + 'value' => self::LESS_THAN, + ], + ], + ] + ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php b/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php new file mode 100644 index 0000000..e4eb27e --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php @@ -0,0 +1,47 @@ + __( 'Status of forms to get. Default is ACTIVE.', 'harness' ), + 'values' => [ + self::ACTIVE => [ + 'description' => __( 'Active forms (default).', 'harness' ), + 'value' => self::ACTIVE, + ], + self::INACTIVE => [ + 'description' => __( 'Inactive forms', 'harness' ), + 'value' => self::INACTIVE, + ], + self::TRASHED => [ + 'description' => __( 'Active forms in the trash.', 'harness' ), + 'value' => self::TRASHED, + ], + self::INACTIVE_TRASHED => [ + 'description' => __( 'Inactive forms in the trash.', 'harness' ), + 'value' => self::INACTIVE_TRASHED, + ], + ], + ] + ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php b/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php new file mode 100644 index 0000000..0db67de --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php @@ -0,0 +1,66 @@ + __( 'Gravity Forms Address field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\InputsProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\LabelPlacementProperty::get(), + FieldProperty\SizeProperty::get(), + [ + // @TODO - Convert to an enum. Possible values: international, us, canadian + 'addressType' => [ + 'type' => 'String', + 'description' => __('Determines the type of address to be displayed.', 'wp-graphql-gravity-forms'), + ], + 'defaultCountry' => [ + 'type' => 'String', + 'description' => __('Contains the country that will be selected by default. Only applicable when "addressType" is set to "international".', 'wp-graphql-gravity-forms'), + ], + 'defaultProvince' => [ + 'type' => 'String', + 'description' => __('Contains the province that will be selected by default. Only applicable when "addressType" is set to "canadian".', 'wp-graphql-gravity-forms'), + ], + 'defaultState' => [ + 'type' => 'String', + 'description' => __('Contains the state that will be selected by default. Only applicable when "addressType" is set to "us".', 'wp-graphql-gravity-forms'), + ], + 'subLabelPlacement' => [ + 'type' => 'String', + 'description' => __( 'The placement of the labels for the fields (street, city, zip/postal code, etc.) within the address group. This setting controls all of the address pieces, they cannot be set individually. They may be aligned above or below the inputs. If this property is not set, the “Sub-Label Placement” setting on the Form Settings->Form Layout page is used. If no setting is specified, the default is above inputs.', 'wp-graphql-gravity-forms' ), + ], + // @TODO - add placeholders. + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php new file mode 100644 index 0000000..6b657e5 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php @@ -0,0 +1,56 @@ + __( 'Gravity Forms Calculation field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionPlacementProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + [ + 'calculationFormula' => [ + 'type' => 'String', + 'description' => __( 'The formula to be used.', 'wp-graphql-gravity-forms' ), + ], + 'enableCalculation' => [ + 'type' => 'Boolean', + 'description' => __( 'Indicates whether the calculation use is active.', 'wp-graphql-gravity-forms '), + ], + // @TODO: Convert to an enum. + 'calculationRounding' => [ + 'type' => 'String', + 'description' => __( 'The number of decimal places the number should be rounded to. Possible values: norounding, 0, 1, 2, 3, 4.', 'wp-graphql-gravity-forms '), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php new file mode 100644 index 0000000..cf1c5e7 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php @@ -0,0 +1,67 @@ + __( 'Gravity Forms CAPTCHA field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\ErrorMessageProperty::get(), + [ + /** + * Possible values: recaptcha, simple_captcha, math + */ + 'captchaType' => [ + 'type' => 'String', + 'description' => __('Determines the type of CAPTCHA field to be used.', 'wp-graphql-gravity-forms'), + ], + /** + * Possible values: red, white, blackglass, clean + */ + 'captchaTheme' => [ + 'type' => 'String', + 'description' => __('Determines the theme to be used for the reCAPTCHA field. Only applicable to the recaptcha captcha type.', 'wp-graphql-gravity-forms'), + ], + /** + * Possible values: small, medium, large + */ + 'simpleCaptchaSize' => [ + 'type' => 'String', + 'description' => __('Determines the CAPTCHA image size. Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), + ], + 'simpleCaptchaFontColor' => [ + 'type' => 'String', + 'description' => __('Determines the image’s font color, in HEX format (i.e. #CCCCCC). Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), + ], + 'simpleCaptchaBackgroundColor' => [ + 'type' => 'String', + 'description' => __('Determines the image’s background color, in HEX format (i.e. #CCCCCC). Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php new file mode 100644 index 0000000..df40446 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php @@ -0,0 +1,56 @@ + __( 'Gravity Forms Chained Select field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputsProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'choices' => [ + 'type' => [ 'list_of' => FieldProperty\ChainedSelectChoiceProperty::TYPE ], + 'description' => __('Choices used to populate the dropdown field. These can be nested multiple levels deep.', 'wp-graphql-gravity-forms'), + ], + // @TODO: Convert to an enum. + 'chainedSelectsAlignment' => [ + 'type' => 'String', + 'description' => __('Alignment of the dropdown fields. Possible values: "horizontal" (in a row) or "vertical" (in a column).', 'wp-graphql-gravity-forms'), + ], + 'chainedSelectsHideInactive' => [ + 'type' => 'Boolean', + 'description' => __('Whether inactive dropdowns should be hidden.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php new file mode 100644 index 0000000..d5358b9 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php @@ -0,0 +1,52 @@ + __( 'Gravity Forms Checkbox field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\ChoicesProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\EnableChoiceValueProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'inputs' => [ + 'type' => [ 'list_of' => FieldProperty\CheckboxInputProperty::TYPE ], + 'description' => __( 'List of inputs. Checkboxes are treated as multi-input fields, since each checkbox item is stored separately.', 'wp-graphql-gravity-forms' ), + ], + 'enableSelectAll' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the "select all" choice should be displayed.', 'wp-graphql-gravity-forms' ), + ] + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php b/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php new file mode 100644 index 0000000..f498596 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php @@ -0,0 +1,63 @@ + __( 'Gravity Forms Date field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get(), + [ + /** + * Possible values: Possible values: calendar, custom, none + */ + 'calendarIconType' => [ + 'type' => 'String', + 'description' => __('Determines how the date field displays it’s calendar icon.', 'wp-graphql-gravity-forms'), + ], + 'calendarIconUrl' => [ + 'type' => 'String', + 'description' => __('Contains the URL to the custom calendar icon. Only applicable when calendarIconType is set to custom.', 'wp-graphql-gravity-forms'), + ], + /** + * Possible values: mdy, dmy + */ + 'dateFormat' => [ + 'type' => 'String', + 'description' => __('Determines how the date is displayed.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php b/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php new file mode 100644 index 0000000..5139920 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php @@ -0,0 +1,43 @@ + __( 'Gravity Forms Email field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/Field.php b/src/classes/WPGraphQLGravityForms/Types/Field/Field.php new file mode 100644 index 0000000..332e97e --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/Field.php @@ -0,0 +1,69 @@ + [ + 'type' => 'String', + 'description' => __( 'When specified, the value of this property will be used on the admin pages instead of the label. It is useful for fields with long labels.', 'wp-graphql-gravity-forms' ), + ], + 'adminOnly' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if this field should only visible on the administration pages. A value of 1 will mark the field as admin only and will hide it from the public form. Useful for fields such as “status” that help with managing entries, but don’t apply to users filling out the form.', 'wp-graphql-gravity-forms' ), + ], + 'allowsPrepopulate' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the field’s value can be pre-populated dynamically. 1 to allow field to be pre-populated, 0 otherwise.', 'wp-graphql-gravity-forms' ), + ], + 'conditionalLogic' => [ + 'type' => ConditionalLogic::TYPE, + 'description' => __( 'Controls the visibility of the field based on values selected by the user.', 'wp-graphql-gravity-forms' ), + ], + 'cssClass' => [ + 'type' => 'String', + 'description' => __( 'String containing the custom CSS classes to be added to the
  • tag that contains the field. Useful for applying custom formatting to specific fields.', 'wp-graphql-gravity-forms' ), + ], + 'cssClassList' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Array of the custom CSS classes to be added to the
  • tag that contains the field. Useful for applying custom formatting to specific fields.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: consider changing this to fieldId so that id can be used for the global Relay ID. + 'id' => [ + 'type' => 'Integer', + 'description' => __( 'Field ID.', 'wp-graphql-gravity-forms' ), + ], + 'label' => [ + 'type' => 'String', + 'description' => __( 'Field label that will be displayed on the form and on the admin pages.', 'wp-graphql-gravity-forms' ), + ], + 'type' => [ + 'type' => 'String', + 'description' => __( 'The type of field to be displayed.', 'wp-graphql-gravity-forms' ), + ], + 'formId' => [ + 'type' => 'Integer', + 'description' => __( 'The ID of the form this field belongs to.', 'wp-graphql-gravity-forms' ), + ], + 'visibility' => [ + 'type' => 'String', + 'description' => __( 'Field visibility. Possible values: visible, hidden, or administrative.', 'wp-graphql-gravity-forms' ), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php new file mode 100644 index 0000000..87562c1 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php @@ -0,0 +1,44 @@ + __('Gravity Forms Chained Select field choice property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'text' => [ + 'type' => 'String', + 'description' => __('The text to be displayed to the user when displaying this choice.', 'wp-graphql-gravity-forms'), + ], + 'value' => [ + 'type' => 'String', + 'description' => __('The value to be stored in the database when this choice is selected.', 'wp-graphql-gravity-forms'), + ], + 'isSelected' => [ + 'type' => 'Boolean', + 'description' => __('Determines if this choice should be selected by default when displayed. The value true will select the choice, whereas false will display it unselected.', 'wp-graphql-gravity-forms'), + ], + 'choices' => [ + 'type' => [ 'list_of' => self::TYPE ], + 'description' => __('Choices used to populate the dropdown field. These can be nested multiple levels deep.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php new file mode 100644 index 0000000..22e3744 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php @@ -0,0 +1,40 @@ + __('Gravity Forms Chained Select field choice property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'id' => [ + 'type' => 'Float', + 'description' => __('The input id. Input Ids follow the following naming convention: “FIELDID.INPUTID” (i.e. 5.1), where FIELDID is the id of the containing field and INPUTID specifies the input field.', 'wp-graphql-gravity-forms'), + ], + 'label' => [ + 'type' => 'String', + 'description' => __('Input label.', 'wp-graphql-gravity-forms'), + ], + 'name' => [ + 'type' => 'String', + 'description' => __('When the field is configured with allowsPrepopulate set to 1, this property contains the parameter name to be used to populate this field (equivalent to the inputName property of single-input fields).', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php new file mode 100644 index 0000000..f0809ce --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php @@ -0,0 +1,42 @@ + __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'text' => [ + 'type' => 'String', + 'description' => __('The text to be displayed to the user when displaying this choice.', 'wp-graphql-gravity-forms'), + ], + 'value' => [ + 'type' => 'String', + 'description' => __('The value to be stored in the database when this choice is selected. Note: This property is only supported by the Drop Down and Post Category fields. Checkboxes and Radio fields will store the text property in the database regardless of the value property.', 'wp-graphql-gravity-forms'), + ], + 'isSelected' => [ + 'type' => 'Boolean', + 'description' => __('Determines if this choice should be selected by default when displayed. The value true will select the choice, whereas false will display it unselected.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php new file mode 100644 index 0000000..01bc945 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php @@ -0,0 +1,26 @@ + [ + 'type' => [ 'list_of' => ChoiceProperty::TYPE ], + 'description' => __('Contains the available choices for the field. For instance, drop down items and checkbox items are configured with this property.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php new file mode 100644 index 0000000..c2f4d82 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php @@ -0,0 +1,22 @@ + [ + 'type' => 'String', + 'description' => __( 'Contains the default value for the field. When specified, the field\'s value will be populated with the contents of this property when the form is displayed.', 'wp-graphql-gravity-forms' ), + ] + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php new file mode 100644 index 0000000..f839d49 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => 'String', + 'description' => __('The placement of the field description. The description may be placed “above” or “below” the field inputs. If the placement is not specified, then the description placement setting for the Form Layout is used.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php new file mode 100644 index 0000000..3ca04cf --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php @@ -0,0 +1,19 @@ + [ + 'type' => 'String', + 'description' => __( 'Field description.', 'wp-graphql-gravity-forms' ), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php new file mode 100644 index 0000000..1f2251c --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => 'Boolean', + 'description' => __('Determines if the field (checkbox, select or radio) have choice values enabled, which allows the field to have choice values different from the labels that are displayed to the user.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php new file mode 100644 index 0000000..fddcd37 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php @@ -0,0 +1,26 @@ + [ + 'type' => 'Boolean', + 'description' => __('When set to true, the "Chosen" jQuery script will be applied to this field, enabling search capabilities to Drop Down fields and a more user-friendly interface for Multi Select fields.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php new file mode 100644 index 0000000..568e145 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => 'String', + 'description' => __('Contains the message that is displayed for fields that fail validation.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php new file mode 100644 index 0000000..74caead --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => 'String', + 'description' => __('Assigns a name to this field so that it can be populated dynamically via this input name. Only applicable when allowsPrepopulate is set to 1.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php new file mode 100644 index 0000000..b4bada6 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php @@ -0,0 +1,48 @@ + __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'id' => [ + 'type' => 'Float', + 'description' => __('The input id. Input Ids follow the following naming convention: “FIELDID.INPUTID” (i.e. 5.1), where FIELDID is the id of the containing field and INPUTID specifies the input field.', 'wp-graphql-gravity-forms'), + ], + 'label' => [ + 'type' => 'String', + 'description' => __('Input label.', 'wp-graphql-gravity-forms'), + ], + 'name' => [ + 'type' => 'String', + 'description' => __('When the field is configured with allowsPrepopulate set to 1, this property contains the parameter name to be used to populate this field (equivalent to the inputName property of single-input fields).', 'wp-graphql-gravity-forms'), + ], + 'key' => [ + 'type' => 'String', + 'description' => __('Key used to identify this input.', 'wp-graphql-gravity-forms'), + ], + 'isHidden' => [ + 'type' => 'Boolean', + 'description' => __('Whether or not this field should be hidden.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php new file mode 100644 index 0000000..e0f0e21 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => [ 'list_of' => InputProperty::TYPE ], + 'description' => __('For fields with multiple inputs (i.e. Name, Address), this property contains a list of inputs. This property also applies to the checkbox field as checkboxes are treated as multi-input fields (since each checkbox item is stored separately).', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php new file mode 100644 index 0000000..3b6998c --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php @@ -0,0 +1,21 @@ + [ + 'type' => 'Boolean', + 'description' => __('Determines if the field requires the user to enter a value. 1 marks the field as required, 0 marks the field as not required. Fields marked as required will prevent the form from being submitted if the user has not entered a value in it.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php new file mode 100644 index 0000000..d46a720 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php @@ -0,0 +1,20 @@ + [ + 'type' => 'String', + 'description' => __( 'The field label position. Empty when using the form defaults or a value of "hidden_label".', 'wp-graphql-gravity-forms' ), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php new file mode 100644 index 0000000..2645156 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php @@ -0,0 +1,38 @@ + __('List field column labels.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'text' => [ + 'type' => 'String', + 'description' => __('The text to be displayed in the column header. Required.', 'wp-graphql-gravity-forms'), + ], + 'value' => [ + 'type' => 'String', + 'description' => __('The text to be displayed in the column header.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php new file mode 100644 index 0000000..a8cc37e --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php @@ -0,0 +1,23 @@ + [ + 'type' => 'Integer', + 'description' => __('Specifies the maximum number of characters allowed in a text or textarea (paragraph) field.', 'wp-graphql-gravity-forms'), + 'resolve' => function( GF_Field $field ) : int { + return (int) $field['maxLength']; + }, + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php new file mode 100644 index 0000000..48de8b9 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php @@ -0,0 +1,42 @@ + __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'text' => [ + 'type' => 'String', + 'description' => __('The text that is displayed.', 'wp-graphql-gravity-forms'), + ], + 'value' => [ + 'type' => 'String', + 'description' => __('The value that is used for the multi select when the form is submitted.', 'wp-graphql-gravity-forms'), + ], + 'isSelected' => [ + 'type' => 'Boolean', + 'description' => __('Indicates whether the item is selected.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php new file mode 100644 index 0000000..ff8c2b4 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php @@ -0,0 +1,22 @@ + [ + 'type' => 'Boolean', + 'description' => __('Determines if the field allows duplicate submissions. 1 to prevent users from submitting the same value more than once, 0 to allow duplicate values.', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php new file mode 100644 index 0000000..4d17651 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php @@ -0,0 +1,46 @@ + __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'id' => [ + 'type' => 'Integer', + 'description' => __('The id of the input field.', 'wp-graphql-gravity-forms'), + ], + 'label' => [ + 'type' => 'String', + 'description' => __('The label for the input.', 'wp-graphql-gravity-forms'), + ], + 'customLabel' => [ + 'type' => 'String', + 'description' => __('The custom label for the input. When set, this is used in place of the label.', 'wp-graphql-gravity-forms'), + ], + 'placeholder' => [ + 'type' => 'String', + 'description' => __('Placeholder text to give the user a hint on how to fill out the field. This is not submitted with the form.', 'wp-graphql-gravity-forms'), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php new file mode 100644 index 0000000..12f210e --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php @@ -0,0 +1,19 @@ + [ + 'type' => 'String', + 'description' => __( 'Field placeholder.', 'wp-graphql-gravity-forms' ), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php new file mode 100644 index 0000000..4b57c16 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php @@ -0,0 +1,23 @@ + [ + 'type' => 'String', + 'description' => __('Determines the size of the field when displayed on the page. Possible values are: "small", "medium", "large".', 'wp-graphql-gravity-forms'), + ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php new file mode 100644 index 0000000..2fedac5 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php @@ -0,0 +1,74 @@ + __( 'Gravity Forms address field values.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'street' => [ + 'type' => 'String', + 'description' => __( 'Street address.', 'wp-graphql-gravity-forms' ), + ], + 'lineTwo' => [ + 'type' => 'String', + 'description' => __( 'Address line two.', 'wp-graphql-gravity-forms' ), + ], + 'city' => [ + 'type' => 'String', + 'description' => __( 'City.', 'wp-graphql-gravity-forms' ), + ], + 'state' => [ + 'type' => 'String', + 'description' => __( 'State / province.', 'wp-graphql-gravity-forms' ), + ], + 'zip' => [ + 'type' => 'String', + 'description' => __( 'ZIP / postal code.', 'wp-graphql-gravity-forms' ), + ], + 'country' => [ + 'type' => 'String', + 'description' => __( 'Country.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'street' => $entry[ $field['inputs'][0]['id'] ], + 'lineTwo' => $entry[ $field['inputs'][1]['id'] ], + 'city' => $entry[ $field['inputs'][2]['id'] ], + 'state' => $entry[ $field['inputs'][3]['id'] ], + 'zip' => $entry[ $field['inputs'][4]['id'] ], + 'country' => $entry[ $field['inputs'][5]['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php new file mode 100644 index 0000000..c64ca91 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php @@ -0,0 +1,51 @@ + __( 'Chained Select field values.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'values' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Field values.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field values. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field values. + */ + public static function get( array $entry, GF_Field $field ) : array { + $values = array_map( function( $input ) use ( $entry ) { + return $entry[ $input['id'] ] ?? ''; + }, $field->inputs ); + + return compact( 'values' ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php new file mode 100644 index 0000000..186f9da --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php @@ -0,0 +1,59 @@ + __( 'Checkbox field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + $field_input_ids = wp_list_pluck( $field->inputs, 'id' ); + $values = []; + + foreach( $entry as $input_id => $value ) { + if ( in_array( $input_id, $field_input_ids, true ) && '' !== $value ) { + $values[] = [ + 'inputId' => $input_id, + 'value' => $value, + ]; + } + } + + return compact( 'values' ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php new file mode 100644 index 0000000..fd15859 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php @@ -0,0 +1,49 @@ + __( 'Date field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php new file mode 100644 index 0000000..4f996c5 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php @@ -0,0 +1,49 @@ + __( 'Email field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php new file mode 100644 index 0000000..a5683e4 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php @@ -0,0 +1,49 @@ + __( 'File upload field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'url' => [ + 'type' => 'String', + 'description' => __( 'URL to the uploaded file.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'url' => isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null, + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php new file mode 100644 index 0000000..191a0d1 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php @@ -0,0 +1,49 @@ + __( 'Multiselect field values.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'values' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Field values.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field values. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field values. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'values' => json_decode( $entry[ $field['id'] ], true ), + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php new file mode 100644 index 0000000..171a50a --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php @@ -0,0 +1,69 @@ + __( 'Name field values.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'prefix' => [ + 'type' => 'String', + 'description' => __( 'Prefix, such as Mr., Mrs. etc.', 'wp-graphql-gravity-forms' ), + ], + 'first' => [ + 'type' => 'String', + 'description' => __( 'First name.', 'wp-graphql-gravity-forms' ), + ], + 'middle' => [ + 'type' => 'String', + 'description' => __( 'Middle name.', 'wp-graphql-gravity-forms' ), + ], + 'last' => [ + 'type' => 'String', + 'description' => __( 'Last name.', 'wp-graphql-gravity-forms' ), + ], + 'suffix' => [ + 'type' => 'String', + 'description' => __( 'Suffix, such as Sr., Jr. etc.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'prefix' => $entry[ $field['inputs'][0]['id'] ], + 'first' => $entry[ $field['inputs'][1]['id'] ], + 'middle' => $entry[ $field['inputs'][2]['id'] ], + 'last' => $entry[ $field['inputs'][3]['id'] ], + 'suffix' => $entry[ $field['inputs'][4]['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php new file mode 100644 index 0000000..c7a7a3e --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php @@ -0,0 +1,49 @@ + __( 'Number field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php new file mode 100644 index 0000000..2d65ad0 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php @@ -0,0 +1,49 @@ + __( 'Phone field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php new file mode 100644 index 0000000..1d2d587 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php @@ -0,0 +1,49 @@ + __( 'Radio field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + $value = isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null; + + return [ 'value' => $value ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php new file mode 100644 index 0000000..cf1fdf2 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php @@ -0,0 +1,49 @@ + __( 'Select field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php new file mode 100644 index 0000000..2f5d44f --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php @@ -0,0 +1,53 @@ + __( 'Signature field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'url' => [ + 'type' => 'String', + 'description' => __( 'The URL to the signature image.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + if ( ! function_exists( 'gf_signature' ) ) { + return []; + } + + return [ + 'url' => gf_signature()->get_signature_url( $entry[ $field['id'] ] ), + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php new file mode 100644 index 0000000..7225be0 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php @@ -0,0 +1,49 @@ + __( 'Textarea field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + $value = isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null; + + return [ 'value' => $value ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php new file mode 100644 index 0000000..9ca48a2 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php @@ -0,0 +1,49 @@ + __( 'Text field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null, + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php new file mode 100644 index 0000000..83a5ab6 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php @@ -0,0 +1,71 @@ + __( 'Time field values.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'displayValue' => [ + 'type' => 'String', + 'description' => __( 'The full display value. Example: "08:25 am".', 'wp-graphql-gravity-forms' ), + ], + 'hours' => [ + 'type' => 'String', + 'description' => __( 'The hours, in this format: hh.', 'wp-graphql-gravity-forms' ), + ], + 'minutes' => [ + 'type' => 'String', + 'description' => __( 'The minutes, in this format: mm.', 'wp-graphql-gravity-forms' ), + ], + 'amPm' => [ + 'type' => 'String', + 'description' => __( 'AM or PM.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + $display_value = $entry[ $field['id'] ]; + $parts_by_colon = explode( ':', $display_value ); + $hours = $parts_by_colon[0] ?? ''; + $parts_by_space = explode( ' ', $display_value ); + $am_pm = $parts_by_space[1] ?? ''; + $minutes = rtrim( ltrim( $display_value, "{$hours}:" ), " {$am_pm}" ); + + return [ + 'displayValue' => $display_value, + 'hours' => $hours, + 'minutes' => $minutes, + 'amPm' => $am_pm, + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php new file mode 100644 index 0000000..05efa1a --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php @@ -0,0 +1,49 @@ + __( 'Website field value.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + /** + * Get the field value. + * + * @param array $entry Gravity Forms entry. + * @param GF_Field $field Gravity Forms field. + * + * @return array Entry field value. + */ + public static function get( array $entry, GF_Field $field ) : array { + return [ + 'value' => (string) $entry[ $field['id'] ], + ]; + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php b/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php new file mode 100644 index 0000000..ca46c63 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php @@ -0,0 +1,40 @@ + __( 'Gravity Forms File Upload field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php b/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php new file mode 100644 index 0000000..c8faf9d --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php @@ -0,0 +1,40 @@ + __( 'Gravity Forms Hidden field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php b/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php new file mode 100644 index 0000000..b934f95 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms HTML field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\InputNameProperty::get(), + [ + 'content' => [ + 'type' => 'String', + 'description' => __( 'Content of an HTML block field to be displayed on the form.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php b/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php new file mode 100644 index 0000000..e836f63 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php @@ -0,0 +1,67 @@ + __( 'Gravity Forms List field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionPlacementProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\LabelPlacementProperty::get(), + [ + 'addIconUrl' => [ + 'type' => 'String', + 'description' => __('The URL of the image to be used for the add row button.', 'wp-graphql-gravity-forms'), + ], + 'choices' => [ + 'type' => [ 'list_of' => FieldProperty\ListChoiceProperty::TYPE ], + 'description' => __('The column labels. Only used when enableColumns is true.', 'wp-graphql-gravity-forms'), + ], + 'deleteIconUrl' => [ + 'type' => 'String', + 'description' => __('The URL of the image to be used for the delete row button.', 'wp-graphql-gravity-forms'), + ], + 'enableColumns' => [ + 'type' => 'Boolean', + 'description' => __('Determines if the field should use multiple columns. Default is false.', 'wp-graphql-gravity-forms'), + ], + 'maxRows' => [ + 'type' => 'Integer', + 'description' => __( 'The maximum number of rows the user can add to the field.', 'wp-graphql-gravity-forms' ), + ], + 'pageNumber' => [ + 'type' => 'Integer', + 'description' => __( 'The form page this field is located on. Default is 1.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php new file mode 100644 index 0000000..8e722c0 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php @@ -0,0 +1,49 @@ + __( 'Gravity Forms Multi-Select field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionPlacementProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\EnableChoiceValueProperty::get(), + FieldProperty\EnableEnhancedUiProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'choices' => [ + 'type' => [ 'list_of' => FieldProperty\MultiSelectChoiceProperty::TYPE ], + 'description' => __('The individual properties for each item in the multi-select.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php b/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php new file mode 100644 index 0000000..a8fdb82 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php @@ -0,0 +1,51 @@ + __( 'Gravity Forms Name field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\InputsProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + /** + * Possible values: normal, extended, simple + */ + 'nameFormat' => [ + 'type' => 'String', + 'description' => __('Determines the format of the name field.', 'wp-graphql-gravity-forms'), + ], + // @TODO: Add placeholders. + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php b/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php new file mode 100644 index 0000000..d8d0988 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php @@ -0,0 +1,60 @@ + __( 'Gravity Forms Number field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get(), + [ + /** + * Possible values: decimal_dot (9,999.99), decimal_comma (9.999,99), currency. + */ + 'numberFormat' => [ + 'type' => 'String', + 'description' => __( 'Specifies the format allowed for the number field.', 'wp-graphql-gravity-forms' ), + ], + 'rangeMin' => [ + 'type' => 'Float', + 'description' => __( 'Minimum allowed value for a number field. Values lower than the number specified by this property will cause the field to fail validation.', 'wp-graphql-gravity-forms' ), + ], + 'rangeMax' => [ + 'type' => 'Float', + 'description' => __( 'Maximum allowed value for a number field. Values higher than the number specified by this property will cause the field to fail validation.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php new file mode 100644 index 0000000..92f7470 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php @@ -0,0 +1,53 @@ + __( 'Gravity Forms Page field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + [ + 'displayOnly' => [ + 'type' => 'Boolean', + 'description' => __('Indicates the field is only displayed and its contents are not submitted with the form/saved with the entry. This is set to true.', 'wp-graphql-gravity-forms'), + ], + 'nextButton' => [ + 'type' => Button::TYPE, + 'description' => __('An array containing the the individual properties for the "Next" button.', 'wp-graphql-gravity-forms'), + ], + 'pageNumber' => [ + 'type' => 'Integer', + 'description' => __('The page number of the current page.', 'wp-graphql-gravity-forms'), + ], + 'previousButton' => [ + 'type' => Button::TYPE, + 'description' => __('An array containing the the individual properties for the "Previous" button.', 'wp-graphql-gravity-forms'), + ], + ] + ) + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php new file mode 100644 index 0000000..abd6385 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php @@ -0,0 +1,55 @@ + __( 'Gravity Forms Password field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionPlacementProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\PlaceholderProperty::get(), + [ + 'inputs' => [ + 'type' => [ 'list_of' => FieldProperty\PasswordInputProperty::TYPE ], + 'description' => __('Individual properties for each element of the password field.', 'wp-graphql-gravity-forms'), + ], + // @TODO: Convert to an enum. + 'minPasswordStrength' => [ + 'type' => 'String', + 'description' => __('Indicates how strong the password should be. The possible values are: short, bad, good, strong.', 'wp-graphql-gravity-forms'), + ], + 'passwordStrengthEnabled' => [ + 'type' => 'Boolean', + 'description' => __('Indicates whether the field displays the password strength indicator.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php new file mode 100644 index 0000000..408e673 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php @@ -0,0 +1,52 @@ + __( 'Gravity Forms Phone field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get(), + [ + /** + * Possible values: standard, international + */ + 'phoneFormat' => [ + 'type' => 'String', + 'description' => __('Determines the allowed format for phones. If the phone value does not conform with the specified format, the field will fail validation.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php new file mode 100644 index 0000000..1f70b70 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php @@ -0,0 +1,47 @@ + __( 'Gravity Forms Post Category field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\ChoicesProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'displayAllCategories' => [ + 'type' => 'Boolean', + 'description' => __('Determines if all categories should be displayed on the Post Category drop down. 1 to display all categories, 0 otherwise. If this property is set to 1 (display all categories), the Post Category drop down will display the categories hierarchically.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php new file mode 100644 index 0000000..ec87e3c --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms Post Content field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php new file mode 100644 index 0000000..f78c1fa --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php @@ -0,0 +1,53 @@ + __( 'Gravity Forms Post Custom Field field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'postCustomFieldName' => [ + 'type' => 'String', + 'description' => __('The name of the Post Custom Field that the submitted value should be assigned to.', 'wp-graphql-gravity-forms'), + ], + 'inputType' => [ + 'type' => 'String', + 'description' => __('Contains a field type and allows a field type to be displayed as another field type. A good example is the Post Custom Field, that can be displayed as various different types of fields.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php new file mode 100644 index 0000000..92e2282 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms Post Excerpt field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php new file mode 100644 index 0000000..78b9330 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php @@ -0,0 +1,54 @@ + __( 'Gravity Forms Post Image field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'displayCaption' => [ + 'type' => 'Boolean', + 'description' => __('Controls the visibility of the caption metadata for Post Image fields. 1 will display the caption field, 0 will hide it.', 'wp-graphql-gravity-forms'), + ], + 'displayDescription' => [ + 'type' => 'Boolean', + 'description' => __('Controls the visibility of the description metadata for Post Image fields. 1 will display the description field, 0 will hide it.', 'wp-graphql-gravity-forms'), + ], + 'displayTitle' => [ + 'type' => 'Boolean', + 'description' => __('Controls the visibility of the title metadata for Post Image fields. 1 will display the title field, 0 will hide it.', 'wp-graphql-gravity-forms'), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php new file mode 100644 index 0000000..4928a22 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms Post Tags field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php new file mode 100644 index 0000000..f86c5ec --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms Post Title field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php b/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php new file mode 100644 index 0000000..1f0b525 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php @@ -0,0 +1,49 @@ + __( 'Gravity Forms Radio field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\ChoicesProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\EnableChoiceValueProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'enableOtherChoice' => [ + 'type' => 'Boolean', + 'description' => __( 'Indicates whether the \'Enable "other" choice\' option is checked in the editor.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php new file mode 100644 index 0000000..7147111 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php @@ -0,0 +1,34 @@ + __( 'Gravity Forms Section field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php new file mode 100644 index 0000000..7d227e2 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php @@ -0,0 +1,45 @@ + __( 'Gravity Forms Select field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\ChoicesProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\EnableChoiceValueProperty::get(), + FieldProperty\EnableEnhancedUiProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php new file mode 100644 index 0000000..7fcffed --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php @@ -0,0 +1,71 @@ + __( 'Gravity Forms Signature field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\IsRequiredProperty::get(), + [ + 'penSize' => [ + 'type' => 'Integer', + 'description' => __( 'Size of the pen cursor.', 'wp-graphql-gravity-forms' ), + ], + 'boxWidth' => [ + 'type' => 'Integer', + 'description' => __( 'Width of the signature field in pixels.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to an enum. + 'borderWidth' => [ + 'type' => 'String', + 'description' => __( 'Width of the border around the signature area. Possible values are: 0 (none), 1 (small), 2 (medium) or 3 (large).', 'wp-graphql-gravity-forms' ), + ], + 'backgroundColor' => [ + 'type' => 'String', + 'description' => __( 'Color to be used for the background of the signature area. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), + ], + 'borderColor' => [ + 'type' => 'String', + 'description' => __( 'Color to be used for the border around the signature area. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to an enum. + 'borderStyle' => [ + 'type' => 'String', + 'description' => __( 'Border style to be used around the signature area. Possible values: dotted, dashed, groove, ridge, inset, outset, double, solid.', 'wp-graphql-gravity-forms' ), + ], + 'penColor' => [ + 'type' => 'String', + 'description' => __( 'Color of the pen to be used for the signature. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php new file mode 100644 index 0000000..0d77588 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php @@ -0,0 +1,44 @@ + __( 'Gravity Forms Textarea (Paragraph Text) field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\MaxLengthProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php new file mode 100644 index 0000000..944b9b2 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php @@ -0,0 +1,50 @@ + __( 'Gravity Forms Single Line Text field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\MaxLengthProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get(), + [ + 'enablePasswordInput' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if a text field input tag should be created with a "password" type.', 'wp-graphql-gravity-forms' ), + ], + ] + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php new file mode 100644 index 0000000..5af9b9f --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php @@ -0,0 +1,42 @@ + __( 'Gravity Forms Time field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\SizeProperty::get() + // @TODO: Add placeholders. + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php b/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php new file mode 100644 index 0000000..accfca9 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php @@ -0,0 +1,43 @@ + __( 'Gravity Forms Website field.', 'wp-graphql-gravity-forms' ), + 'fields' => array_merge( + $this->get_global_properties(), + FieldProperty\DefaultValueProperty::get(), + FieldProperty\DescriptionProperty::get(), + FieldProperty\ErrorMessageProperty::get(), + FieldProperty\InputNameProperty::get(), + FieldProperty\IsRequiredProperty::get(), + FieldProperty\NoDuplicatesProperty::get(), + FieldProperty\PlaceholderProperty::get(), + FieldProperty\SizeProperty::get() + ), + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php b/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php new file mode 100644 index 0000000..6dca51f --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php @@ -0,0 +1,29 @@ + __( 'Field error.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'message' => [ + 'type' => 'String', + 'description' => __( 'Error message.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/Form.php b/src/classes/WPGraphQLGravityForms/Types/Form/Form.php new file mode 100644 index 0000000..6bf5480 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/Form.php @@ -0,0 +1,285 @@ +form_data_manipulator = $form_data_manipulator; + } + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register_type' ] ); + add_action( 'graphql_register_types', [ $this, 'register_field' ] ); + } + + public function register_type() { + register_graphql_object_type( self::TYPE, [ + 'description' => __( 'Gravity Forms form.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( 'Unique global ID for the object.', 'wp-graphql-gravity-forms' ), + ], + 'formId' => [ + 'type' => 'Int', + 'description' => __( 'Form ID.', 'wp-graphql-gravity-forms' ), + ], + 'title' => [ + 'type' => 'String', + 'description' => __( 'Form title.', 'wp-graphql-gravity-forms' ), + ], + 'description' => [ + 'type' => 'String', + 'description' => __( 'Form description.', 'wp-graphql-gravity-forms' ), + ], + // @TODO - Convert to enum. Possible values: top_label, left_label, right_label + 'labelPlacement' => [ + 'type' => 'String', + 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-gravity-forms' ), + ], + // @TODO - Convert to enum. Possible values: above, below + 'descriptionPlacement' => [ + 'type' => 'String', + 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-gravity-forms' ), + ], + 'button' => [ + 'type' => Button::TYPE, + 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-gravity-forms' ), + ], + 'useCurrentUserAsAuthor' => [ + 'type' => 'Boolean', + 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-gravity-forms' ), + ], + 'postContentTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-gravity-forms' ), + ], + 'postTitleTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-gravity-forms' ), + ], + 'postTitleTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-gravity-forms' ), + ], + 'postContentTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-gravity-forms' ), + ], + 'lastPageButton' => [ + 'type' => Button::TYPE, + 'description' => __( 'Last page button data.', 'wp-graphql-gravity-forms' ), + ], + 'pagination' => [ + 'type' => FormPagination::TYPE, + 'description' => __( 'Pagination data.', 'wp-graphql-gravity-forms' ), + ], + 'firstPageCssClass' => [ + 'type' => 'String', + 'description' => __( 'CSS class for the first page.', 'wp-graphql-gravity-forms' ), + ], + 'postAuthor' => [ + 'type' => 'Int', + 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-gravity-forms' ), + ], + 'postCategory' => [ + 'type' => 'Int', + 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-gravity-forms' ), + ], + 'postFormat' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-gravity-forms' ), + ], + 'postStatus' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to an enum. https://docs.gravityforms.com/gf_field_name/ + 'subLabelPlacement' => [ + 'type' => 'String', + 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-gravity-forms' ), + ], + 'cssClass' => [ + 'type' => 'String', + 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-gravity-forms' ), + ], + 'cssClassList' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-gravity-forms' ), + ], + 'enableHoneypot' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-gravity-forms' ), + ], + 'enableAnimation' => [ + 'type' => 'Boolean', + 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-gravity-forms' ), + ], + 'save' => [ + 'type' => SaveAndContinue::TYPE, + 'description' => __( '"Save and Continue" data.', 'wp-graphql-gravity-forms' ), + ], + 'limitEntries' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-gravity-forms' ), + ], + 'limitEntriesCount' => [ + 'type' => 'Int', + 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to an enum. + 'limitEntriesPeriod' => [ + 'type' => 'String', + 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-gravity-forms' ), + ], + 'limitEntriesMessage' => [ + 'type' => 'String', + 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleForm' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleStart' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleStartHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleStartMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleStartAmpm' => [ + 'type' => 'String', + 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-gravity-forms' ), + ], + 'scheduleEnd' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleEndHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleEndMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleEndAmpm' => [ + 'type' => 'String', + 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-gravity-forms' ), + ], + 'schedulePendingMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-gravity-forms' ), + ], + 'scheduleMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-gravity-forms' ), + ], + 'requireLogin' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-gravity-forms' ), + ], + 'requireLoginMessage' => [ + 'type' => 'String', + 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-gravity-forms' ), + ], + 'notifications' => [ + 'type' => [ 'list_of' => FormNotification::TYPE ], + 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), + ], + 'confirmations' => [ + 'type' => [ 'list_of' => FormConfirmation::TYPE ], + 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-gravity-forms' ), + ], + 'nextFieldId' => [ + 'type' => 'Int', + 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-gravity-forms' ), + ], + 'isActive' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is active.', 'wp-graphql-gravity-forms' ), + ], + 'dateCreated' => [ + 'type' => 'String', + 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-gravity-forms' ), + ], + 'isTrash' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } + + public function register_field() { + register_graphql_field( 'RootQuery', self::FIELD, [ + 'description' => __( 'Get a Gravity Forms form.', 'wp-graphql-gravity-forms' ), + 'type' => self::TYPE, + 'args' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( "Unique global ID for the object. Base-64 encode a string like this, where '123' is the form ID: '{self::TYPE}:123'.", 'wp-graphql-gravity-forms' ), + ], + ], + 'resolve' => function( $root, array $args ) : array { + $id_parts = Relay::fromGlobalId( $args['id'] ); + + if ( ! is_array( $id_parts ) || empty( $id_parts['id'] ) || empty( $id_parts['type'] ) ) { + throw new UserError( __( 'A valid global ID must be provided.', 'wp-graphql-gravity-forms' ) ); + } + + $form_raw = GFAPI::get_form( $id_parts['id'] ); + + if ( ! $form_raw ) { + throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-gravity-forms' ) ); + } + + $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); + + /** + * Provides the ability to manipulate the form data before it is sent to the + * client. This hook is somewhat similar to Gravity Forms' gform_pre_render hook + * and can be used for dynamic field input population, among other things. + * + * @param array $form Form meta array. + */ + return apply_filters( 'wp_graphql_gf_form_object', $form ); + } + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php new file mode 100644 index 0000000..c3a06b4 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php @@ -0,0 +1,59 @@ + __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'id' => [ + 'type' => 'String', + 'description' => __( 'ID.', 'wp-graphql-gravity-forms' ), + ], + 'name' => [ + 'type' => 'String', + 'description' => __( 'Name.', 'wp-graphql-gravity-forms' ), + ], + 'isDefault' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether this is the default confirmation.', 'wp-graphql-gravity-forms' ), + ], + 'type' => [ + 'type' => 'String', + 'description' => __( 'Determines the type of confirmation to be used. Possible values: message, page, redirect.', 'wp-graphql-gravity-forms' ), + ], + 'message' => [ + 'type' => 'String', + 'description' => __( 'Contains the confirmation message that will be displayed. Only applicable when type is set to message.', 'wp-graphql-gravity-forms' ), + ], + 'url' => [ + 'type' => 'String', + 'description' => __( 'Contains the URL that the browser will be redirected to. Only applicable when type is set to redirect.', 'wp-graphql-gravity-forms' ), + ], + 'pageId' => [ + 'type' => 'Integer', + 'description' => __( 'Contains the Id of the WordPress page that the browser will be redirected to. Only applicable when type is set to page.', 'wp-graphql-gravity-forms' ), + ], + 'queryString' => [ + 'type' => 'String', + 'description' => __( 'Contains the query string to be appended to the redirection url. Only applicable when type is set to redirect.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php new file mode 100644 index 0000000..76515c5 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php @@ -0,0 +1,96 @@ + __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'isActive' => [ + 'type' => 'Boolean', + 'description' => __( 'Is the notification active or inactive. The default is true (active).', 'wp-graphql-gravity-forms' ), + ], + 'id' => [ + 'type' => 'String', + 'description' => __( 'The notification ID. A 13 character unique ID.', 'wp-graphql-gravity-forms' ), + ], + 'name' => [ + 'type' => 'String', + 'description' => __( 'The notification name.', 'wp-graphql-gravity-forms' ), + ], + 'service' => [ + 'type' => 'String', + 'description' => __( 'The name of the service to be used when sending this notification. Default is wordpress.', 'wp-graphql-gravity-forms' ), + ], + 'event' => [ + 'type' => 'String', + 'description' => __( 'The notification event. Default is form_submission.', 'wp-graphql-gravity-forms' ), + ], + 'to' => [ + 'type' => 'String', + 'description' => __( 'The ID of an email field, an email address or merge tag to be used as the email to address.', 'wp-graphql-gravity-forms' ), + ], + 'toType' => [ + 'type' => 'String', + 'description' => __( 'Identifies what to use for the notification to. Possible values: email, field, routing or hidden.', 'wp-graphql-gravity-forms' ), + ], + 'bcc' => [ + 'type' => 'String', + 'description' => __( 'The email or merge tags to be used as the email bcc address.', 'wp-graphql-gravity-forms' ), + ], + 'subject' => [ + 'type' => 'String', + 'description' => __( 'The email subject line. Merge tags supported.', 'wp-graphql-gravity-forms' ), + ], + 'message' => [ + 'type' => 'String', + 'description' => __( 'The email body/content. Merge tags supported.', 'wp-graphql-gravity-forms' ), + ], + 'from' => [ + 'type' => 'String', + 'description' => __( 'The email or merge tag to be used as the email from address.', 'wp-graphql-gravity-forms' ), + ], + 'fromName' => [ + 'type' => 'String', + 'description' => __( 'The text or merge tag to be used as the email from name.', 'wp-graphql-gravity-forms' ), + ], + 'replyTo' => [ + 'type' => 'String', + 'description' => __( 'The email or merge tags to be used as the email reply to address.', 'wp-graphql-gravity-forms' ), + ], + 'routing' => [ + 'type' => [ 'list_of' => FormNotificationRouting::TYPE ], + 'description' => __( 'Routing rules.', 'wp-graphql-gravity-forms' ), + ], + 'conditionalLogic' => [ + 'type' => ConditionalLogic::TYPE, + 'description' => __( 'An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.', 'wp-graphql-gravity-forms' ), + ], + 'disableAutoformat' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the email message should be formatted so that paragraphs are automatically added for new lines. Default is false (auto-formatting enabled).', 'wp-graphql-gravity-forms' ), + ], + 'enableAttachments' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if files uploaded on the form should be included when the notification is sent.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php new file mode 100644 index 0000000..915dbcd --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php @@ -0,0 +1,44 @@ + __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'fieldId' => [ + 'type' => 'String', + 'description' => __( 'Target field ID. The field that will have it’s value compared with the value property to determine if this rule is a match.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: convert to an enum. + 'operator' => [ + 'type' => 'String', + 'description' => __( 'Operator to be used when evaluating this rule. Possible values: is, isnot, >, <, contains, starts_with, or ends_with.', 'wp-graphql-gravity-forms' ), + ], + 'value' => [ + 'type' => 'String', + 'description' => __( 'The value to compare with the field specified by fieldId.', 'wp-graphql-gravity-forms' ), + ], + 'email' => [ + 'type' => 'String', + 'description' => __( 'The email or merge tag to be used as the email To address if this rule is a match.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php new file mode 100644 index 0000000..f25e784 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php @@ -0,0 +1,57 @@ + __( 'Gravity Forms form pagination data.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + // @TODO - convert to enum + 'type' => [ + 'type' => 'String', + 'description' => __( 'Type of progress indicator. Possible values are: percentage, steps or none.', 'wp-graphql-gravity-forms' ), + ], + 'pages' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Names of the form\'s pages.', 'wp-graphql-gravity-forms' ), + ], + // @TODO - convert to enum + 'style' => [ + 'type' => 'String', + 'description' => __( 'Style of progress bar. Possible values are: blue, gray, green, orange, red or custom.', 'wp-graphql-gravity-forms' ), + ], + 'backgroundColor' => [ + 'type' => 'String', + 'description' => __( 'Progress bar background color. Can be any CSS color value. Only applies when "style" is set to "custom".', 'wp-graphql-gravity-forms' ), + ], + 'color' => [ + 'type' => 'String', + 'description' => __( 'Progress bar text color. Can be any CSS color value. Only applies when "style" is set to "custom".', 'wp-graphql-gravity-forms' ), + ], + 'displayProgressbarOnConfirmation' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the confirmation bar should be displayed with the confirmation text.', 'wp-graphql-gravity-forms' ), + ], + 'progressbarCompletionText' => [ + 'type' => 'String', + 'description' => __( 'The confirmation text to display once the end of the progress bar has been reached. Only applies when displayProgressbarOnConfirmation is set to true.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php b/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php new file mode 100644 index 0000000..3f6f704 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php @@ -0,0 +1,34 @@ + __( 'Gravity Forms form Save and Continue data.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'enabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the Save And Continue feature is enabled.', 'wp-graphql-gravity-forms' ), + ], + 'button' => [ + 'type' => Button::TYPE, + 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php new file mode 100644 index 0000000..167b78d --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php @@ -0,0 +1,36 @@ + __( 'Input fields for a single checkbox.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'inputId' => [ + 'type' => 'Float', + 'description' => __( 'Input ID.', 'wp-graphql-gravity-forms' ), + ], + 'value' => [ + 'type' => 'String', + 'description' => __( 'Input value', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php new file mode 100644 index 0000000..44184bd --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php @@ -0,0 +1,36 @@ + __('Date Filters input fields for Entries queries.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'startDate' => [ + 'type' => 'String', + 'description' => __( 'Start date in Y-m-d H:i:s format.', 'wp-graphql-gravity-forms' ), + ], + 'endDate' => [ + 'type' => 'String', + 'description' => __( 'End date in Y-m-d H:i:s format.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php new file mode 100644 index 0000000..44f1e7b --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php @@ -0,0 +1,54 @@ + __( 'Field Filters input fields for Entries queries.', 'wp-graphql-gravity-forms' ), + 'fields' => [ + 'key' => [ + 'type' => 'String', + 'description' => __( 'The ID of the field to filter by. Use "0" to search all keys. You can also use the names of the columns in Gravity Forms\' database table for entries, such as "date_created", "is_read, "created_by", etc.', 'wp-graphql-gravity-forms' ), + ], + 'operator' => [ + 'type' => FieldFiltersOperatorInputEnum::TYPE, + 'description' => __( 'The operator to use for filtering.', 'wp-graphql-gravity-forms' ), + ], + // @TODO - Is there a cleaner way to do this? Values can be any of these types. + 'stringValues' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'The field value(s) to filter by. Must be string values. If using this field, do not also use intValues, floatValues or boolValues.', 'wp-graphql-gravity-forms' ), + ], + 'intValues' => [ + 'type' => [ 'list_of' => 'Int' ], + 'description' => __( 'The field value(s) to filter by. Must be integer values. If using this field, do not also use stringValues, floatValues or boolValues.', 'wp-graphql-gravity-forms' ), + ], + 'floatValues' => [ + 'type' => [ 'list_of' => 'Float' ], + 'description' => __( 'The field value(s) to filter by. Must be float values. If using this field, do not also use stringValues, intValues or boolValues.', 'wp-graphql-gravity-forms' ), + ], + 'boolValues' => [ + 'type' => [ 'list_of' => 'Boolean' ], + 'description' => __( 'The field value(s) to filter by. Must be boolean values. If using this field, do not also use stringValues, intValues or floatValues.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php new file mode 100644 index 0000000..7328595 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php @@ -0,0 +1,41 @@ + __('Sorting input fields for Entries queries.', 'wp-graphql-gravity-forms'), + 'fields' => [ + 'key' => [ + 'type' => 'String', + 'description' => __( 'The key of the field to sort by.', 'wp-graphql-gravity-forms' ), + ], + // @TODO: Convert to enum. + 'direction' => [ + 'type' => 'String', + 'description' => __( 'The sorting direction. Possible values: DESC for descending (default), or ASC for ascending.', 'wp-graphql-gravity-forms' ), + ], + 'isNumeric' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the sorting field\'s values are numeric.', 'wp-graphql-gravity-forms' ), + ], + ], + ] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php new file mode 100644 index 0000000..1dd06b1 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php @@ -0,0 +1,78 @@ +instances = $instances; + } + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register_type' ], 11 ); + } + + public function register_type( TypeRegistry $type_registry ) { + $field_mappings = $this->get_field_type_mappings(); + + register_graphql_union_type( self::TYPE, [ + 'typeNames' => array_values( $field_mappings ), + 'resolveType' => function( GF_Field $field ) use ( $field_mappings, $type_registry ) { + if ( isset( $field_mappings[ $field['type'] ] ) ) { + return $type_registry->get_type( $field_mappings[ $field['type'] ] ); + } + + return null; + }, + ] ); + } + + /** + * Get mappings from the field types registered in Gravity Forms + * to the corresponding field types registered in WPGraphQL. + * Example: [ 'textarea' => 'TextAreaField' ] + * + * @return array Field type mappings. + */ + private function get_field_type_mappings() : array { + $fields = array_filter( $this->instances, function( $instance ) { + return $instance instanceof Field; + } ); + + /** + * Filter for adding custom field class instances to be used by this union's resolver. + * + * @param array $fields Gravity Forms field class instances. + */ + $fields = apply_filters( 'wp_graphql_gf_form_field_instances', $fields ); + + return array_reduce( $fields, function( $mappings, $field ) { + $mappings[ $field::GF_TYPE ] = $field::TYPE; + + return $mappings; + }, [] ); + } +} diff --git a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php new file mode 100644 index 0000000..a1219e3 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php @@ -0,0 +1,80 @@ +instances = $instances; + } + + public function register_hooks() { + add_action( 'graphql_register_types', [ $this, 'register_type' ], 11 ); + } + + public function register_type( $type_registry ) { + $field_value_types = $this->get_field_value_types(); + register_graphql_union_type( self::TYPE, [ + 'typeNames' => array_unique( array_values( $field_value_types ) ), + 'resolveType' => function( $object ) use ( $field_value_types, $type_registry ) { + if ( isset( $field_value_types[ $object['type'] ] ) ) { + return $type_registry->get_type( $field_value_types[ $object['type'] ] ); + } + + return null; + }, + ] ); + } + + + /** + * Get field types and their related field value types. + * Example: [ 'AddressField' => 'AddressFieldValues' ] + * + * @return array Field value types. + */ + private function get_field_value_types() : array { + $fields_with_value_types = array_filter( $this->instances, function( $instance ) { + return $instance instanceof Field && $this->does_field_have_value_type( $instance ); + } ); + + return array_reduce( $fields_with_value_types, function( $value_types, $field ) { + $value_types[ $field::TYPE ] = $field::TYPE . 'Value'; + + return $value_types; + }, [] ); + } + + /** + * @param Field $field Gravity Forms field. + * + * @return bool Whether $field has a corresponding field value type. + */ + private function does_field_have_value_type( Field $field ) : bool { + return class_exists( 'WPGraphQLGravityForms\Types\Field\FieldValue\\' . $field::TYPE . 'Value' ); + } +} From f70340134b4302b35e7a159052670d49e8e7638f Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 10:25:20 +0200 Subject: [PATCH 08/17] Load WPGraphQLGravityForms class --- src/class-acf.php | 1 + .../WPGraphQLGravityForms.php | 184 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php diff --git a/src/class-acf.php b/src/class-acf.php index c925a25..79a7401 100644 --- a/src/class-acf.php +++ b/src/class-acf.php @@ -117,6 +117,7 @@ private function setup_constants() { private function includes() { // Autoload Required Classes. + require_once(plugin_dir_path( __FILE__ ) . '/classes/WPGraphQLGravityForms.php'); } /** diff --git a/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php b/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php new file mode 100644 index 0000000..d234902 --- /dev/null +++ b/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php @@ -0,0 +1,184 @@ +create_instances(); + $this->register_hooks(); + } + + private function create_instances() { + // Data manipulators + $this->instances['fields_data_manipulator'] = new DataManipulators\FieldsDataManipulator(); + $this->instances['form_data_manipulator'] = new DataManipulators\FormDataManipulator( $this->instances['fields_data_manipulator'] ); + $this->instances['entry_data_manipulator'] = new DataManipulators\EntryDataManipulator(); + $this->instances['draft_entry_data_manipulator'] = new DataManipulators\DraftEntryDataManipulator( $this->instances['entry_data_manipulator'] ); + + // Buttons + $this->instances['button'] = new Button(); + + // Conditional Logic + $this->instances['conditional_logic'] = new ConditionalLogic\ConditionalLogic(); + $this->instances['conditional_logic_rule'] = new ConditionalLogic\ConditionalLogicRule(); + + // Forms + $this->instances['save_and_continue'] = new Form\SaveAndContinue(); + $this->instances['form_notification_routing'] = new Form\FormNotificationRouting(); + $this->instances['form_notification'] = new Form\FormNotification(); + $this->instances['form_confirmation'] = new Form\FormConfirmation(); + $this->instances['form_pagination'] = new Form\FormPagination(); + $this->instances['form'] = new Form\Form( $this->instances['form_data_manipulator'] ); + + // Fields + $this->instances['address_field'] = new Field\AddressField(); + $this->instances['calculation_field'] = new Field\CalculationField(); + $this->instances['captcha_field'] = new Field\CaptchaField(); + $this->instances['chained_select_field'] = new Field\ChainedSelectField(); + $this->instances['checkbox_field'] = new Field\CheckboxField(); + $this->instances['date_field'] = new Field\DateField(); + $this->instances['email_field'] = new Field\EmailField(); + $this->instances['file_upload_field'] = new Field\FileUploadField(); + $this->instances['hidden_field'] = new Field\HiddenField(); + $this->instances['html_field'] = new Field\HtmlField(); + $this->instances['list_field'] = new Field\ListField(); + $this->instances['multi_select_field'] = new Field\MultiSelectField(); + $this->instances['name_field'] = new Field\NameField(); + $this->instances['number_field'] = new Field\NumberField(); + $this->instances['page_field'] = new Field\PageField(); + $this->instances['password_field'] = new Field\PasswordField(); + $this->instances['phone_field'] = new Field\PhoneField(); + $this->instances['post_category_field'] = new Field\PostCategoryField(); + $this->instances['post_content_field'] = new Field\PostContentField(); + $this->instances['post_custom_field'] = new Field\PostCustomField(); + $this->instances['post_excerpt_field'] = new Field\PostExcerptField(); + $this->instances['post_image_field'] = new Field\PostImageField(); + $this->instances['post_tags_field'] = new Field\PostTagsField(); + $this->instances['post_title_field'] = new Field\PostTitleField(); + $this->instances['radio_field'] = new Field\RadioField(); + $this->instances['section_field'] = new Field\SectionField(); + $this->instances['signature_field'] = new Field\SignatureField(); + $this->instances['select_field'] = new Field\SelectField(); + $this->instances['text_area_field'] = new Field\TextAreaField(); + $this->instances['text_field'] = new Field\TextField(); + $this->instances['time_field'] = new Field\TimeField(); + $this->instances['website_field'] = new Field\WebsiteField(); + + // Field Properties + $this->instances['chained_select_choice_property'] = new FieldProperty\ChainedSelectChoiceProperty(); + $this->instances['checkbox_input_property'] = new FieldProperty\CheckboxInputProperty(); + $this->instances['choice_property'] = new FieldProperty\ChoiceProperty(); + $this->instances['input_property'] = new FieldProperty\InputProperty(); + $this->instances['list_choice_property'] = new FieldProperty\ListChoiceProperty(); + $this->instances['multi_select_choice_property'] = new FieldProperty\MultiSelectChoiceProperty(); + $this->instances['password_input_property'] = new FieldProperty\PasswordInputProperty(); + + // Field Values + $this->instances['address_field_value'] = new FieldValue\AddressFieldValue(); + $this->instances['chained_select_field_value'] = new FieldValue\ChainedSelectFieldValue(); + $this->instances['checkbox_field_values'] = new FieldValue\CheckboxFieldValue(); + $this->instances['date_field_values'] = new FieldValue\DateFieldValue(); + $this->instances['email_field_value'] = new FieldValue\EmailFieldValue(); + $this->instances['file_upload_field_value'] = new FieldValue\FileUploadFieldValue(); + $this->instances['multi_select_field_value'] = new FieldValue\MultiSelectFieldValue(); + $this->instances['name_field_value'] = new FieldValue\NameFieldValue(); + $this->instances['number_field_value'] = new FieldValue\NumberFieldValue(); + $this->instances['phone_field_values'] = new FieldValue\PhoneFieldValue(); + $this->instances['radio_field_values'] = new FieldValue\RadioFieldValue(); + $this->instances['select_field_value'] = new FieldValue\SelectFieldValue(); + $this->instances['signature_field_value'] = new FieldValue\SignatureFieldValue(); + $this->instances['text_area_field_value'] = new FieldValue\TextAreaFieldValue(); + $this->instances['text_field_value'] = new FieldValue\TextFieldValue(); + $this->instances['time_field_value'] = new FieldValue\TimeFieldValue(); + $this->instances['website_field_value'] = new FieldValue\WebsiteFieldValue(); + + // Entries + $this->instances['entry'] = new Entry\Entry( $this->instances['entry_data_manipulator'], $this->instances['draft_entry_data_manipulator'] ); + $this->instances['entry_form'] = new Entry\EntryForm( $this->instances['form_data_manipulator'] ); + $this->instances['entry_user'] = new Entry\EntryUser(); + + // Input + $this->instances['checkbox_input'] = new Input\CheckboxInput(); + $this->instances['entries_date_fiters_input'] = new Input\EntriesDateFiltersInput(); + $this->instances['entries_field_fiters_input'] = new Input\EntriesFieldFiltersInput(); + $this->instances['entries_sorting_input'] = new Input\EntriesSortingInput(); + + // Unions + $this->instances['object_field_union'] = new Union\ObjectFieldUnion( $this->instances ); + $this->instances['object_field_value_union'] = new Union\ObjectFieldValueUnion( $this->instances ); + + // Connections + $this->instances['entry_field_connection'] = new Connections\EntryFieldConnection( $this->instances ); + $this->instances['form_field_connection'] = new Connections\FormFieldConnection(); + $this->instances['root_query_entries_connection'] = new Connections\RootQueryEntriesConnection(); + $this->instances['root_query_forms_connection'] = new Connections\RootQueryFormsConnection(); + + // Enums + $this->instances['form_status_enum'] = new Enum\FormStatusEnum(); + $this->instances['field_filters_operator_input_enum'] = new Enum\FieldFiltersOperatorInputEnum(); + + // Field errors + $this->instances['field_error'] = new FieldError(); + + // Draft entry mutations + $this->instances['create_draft_entry'] = new Mutations\CreateDraftEntry(); + $this->instances['delete_draft_entry'] = new Mutations\DeleteDraftEntry(); + $this->instances['submit_draft_entry'] = new Mutations\SubmitDraftEntry( $this->instances['entry_data_manipulator'] ); + $this->instances['update_draft_entry_checkbox_field_value'] = new Mutations\UpdateDraftEntryCheckboxFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_date_field_value'] = new Mutations\UpdateDraftEntryDateFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_email_field_value'] = new Mutations\UpdateDraftEntryEmailFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_multi_select_field_value'] = new Mutations\UpdateDraftEntryMultiSelectFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_number_field_value'] = new Mutations\UpdateDraftEntryNumberFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_phone_field_value'] = new Mutations\UpdateDraftEntryPhoneFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_radio_field_value'] = new Mutations\UpdateDraftEntryRadioFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_select_field_value'] = new Mutations\UpdateDraftEntrySelectFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_signature_field_value'] = new Mutations\UpdateDraftEntrySignatureFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_text_area_field_value'] = new Mutations\UpdateDraftEntryTextAreaFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_text_field_value'] = new Mutations\UpdateDraftEntryTextFieldValue( $this->instances['draft_entry_data_manipulator'] ); + $this->instances['update_draft_entry_website_field_value'] = new Mutations\UpdateDraftEntryWebsiteFieldValue( $this->instances['draft_entry_data_manipulator'] ); + } + + private function register_hooks() { + foreach ( $this->get_hookable_instances() as $instance ) { + $instance->register_hooks(); + } + } + + private function get_hookable_instances() { + return array_filter( $this->instances, function( $instance ) { + return $instance instanceof Hookable; + } ); + } +} + +// @TODO: Handle this more gracefully to bump up the number of form fields returned. +add_filter( 'graphql_connection_max_query_amount', function() { + return 500; +}, 11 ); From f3c2a62e3b8ae760f2ddee6bb6d4666b1387490c Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 10:59:36 +0200 Subject: [PATCH 09/17] Remove WPGraphQLGravityForms --- src/class-acf.php | 1 - .../Types/Button/Button.php | 45 --- .../ConditionalLogic/ConditionalLogic.php | 41 --- .../ConditionalLogic/ConditionalLogicRule.php | 40 --- .../Types/Entry/Entry.php | 181 ----------- .../Types/Entry/EntryForm.php | 74 ----- .../Types/Entry/EntryUser.php | 64 ---- .../Enum/FieldFiltersOperatorInputEnum.php | 52 ---- .../Types/Enum/FormStatusEnum.php | 47 --- .../Types/Field/AddressField.php | 66 ---- .../Types/Field/CalculationField.php | 56 ---- .../Types/Field/CaptchaField.php | 67 ---- .../Types/Field/ChainedSelectField.php | 56 ---- .../Types/Field/CheckboxField.php | 52 ---- .../Types/Field/DateField.php | 63 ---- .../Types/Field/EmailField.php | 43 --- .../Types/Field/Field.php | 69 ----- .../ChainedSelectChoiceProperty.php | 44 --- .../FieldProperty/CheckboxInputProperty.php | 40 --- .../Field/FieldProperty/ChoiceProperty.php | 42 --- .../Field/FieldProperty/ChoicesProperty.php | 26 -- .../FieldProperty/DefaultValueProperty.php | 22 -- .../DescriptionPlacementProperty.php | 21 -- .../FieldProperty/DescriptionProperty.php | 19 -- .../EnableChoiceValueProperty.php | 21 -- .../EnableEnhancedUiProperty.php | 26 -- .../FieldProperty/ErrorMessageProperty.php | 21 -- .../Field/FieldProperty/InputNameProperty.php | 21 -- .../Field/FieldProperty/InputProperty.php | 48 --- .../Field/FieldProperty/InputsProperty.php | 21 -- .../FieldProperty/IsRequiredProperty.php | 21 -- .../FieldProperty/LabelPlacementProperty.php | 20 -- .../FieldProperty/ListChoiceProperty.php | 38 --- .../Field/FieldProperty/MaxLengthProperty.php | 23 -- .../MultiSelectChoiceProperty.php | 42 --- .../FieldProperty/NoDuplicatesProperty.php | 22 -- .../FieldProperty/PasswordInputProperty.php | 46 --- .../FieldProperty/PlaceholderProperty.php | 19 -- .../Field/FieldProperty/SizeProperty.php | 23 -- .../Field/FieldValue/AddressFieldValue.php | 74 ----- .../FieldValue/ChainedSelectFieldValue.php | 51 ---- .../Field/FieldValue/CheckboxFieldValue.php | 59 ---- .../Types/Field/FieldValue/DateFieldValue.php | 49 --- .../Field/FieldValue/EmailFieldValue.php | 49 --- .../Field/FieldValue/FileUploadFieldValue.php | 49 --- .../FieldValue/MultiSelectFieldValue.php | 49 --- .../Types/Field/FieldValue/NameFieldValue.php | 69 ----- .../Field/FieldValue/NumberFieldValue.php | 49 --- .../Field/FieldValue/PhoneFieldValue.php | 49 --- .../Field/FieldValue/RadioFieldValue.php | 49 --- .../Field/FieldValue/SelectFieldValue.php | 49 --- .../Field/FieldValue/SignatureFieldValue.php | 53 ---- .../Field/FieldValue/TextAreaFieldValue.php | 49 --- .../Types/Field/FieldValue/TextFieldValue.php | 49 --- .../Types/Field/FieldValue/TimeFieldValue.php | 71 ----- .../Field/FieldValue/WebsiteFieldValue.php | 49 --- .../Types/Field/FileUploadField.php | 40 --- .../Types/Field/HiddenField.php | 40 --- .../Types/Field/HtmlField.php | 42 --- .../Types/Field/ListField.php | 67 ---- .../Types/Field/MultiSelectField.php | 49 --- .../Types/Field/NameField.php | 51 ---- .../Types/Field/NumberField.php | 60 ---- .../Types/Field/PageField.php | 53 ---- .../Types/Field/PasswordField.php | 55 ---- .../Types/Field/PhoneField.php | 52 ---- .../Types/Field/PostCategoryField.php | 47 --- .../Types/Field/PostContentField.php | 42 --- .../Types/Field/PostCustomField.php | 53 ---- .../Types/Field/PostExcerptField.php | 42 --- .../Types/Field/PostImageField.php | 54 ---- .../Types/Field/PostTagsField.php | 42 --- .../Types/Field/PostTitleField.php | 42 --- .../Types/Field/RadioField.php | 49 --- .../Types/Field/SectionField.php | 34 --- .../Types/Field/SelectField.php | 45 --- .../Types/Field/SignatureField.php | 71 ----- .../Types/Field/TextAreaField.php | 44 --- .../Types/Field/TextField.php | 50 --- .../Types/Field/TimeField.php | 42 --- .../Types/Field/WebsiteField.php | 43 --- .../Types/FieldError/FieldError.php | 29 -- .../WPGraphQLGravityForms/Types/Form/Form.php | 285 ------------------ .../Types/Form/FormConfirmation.php | 59 ---- .../Types/Form/FormNotification.php | 96 ------ .../Types/Form/FormNotificationRouting.php | 44 --- .../Types/Form/FormPagination.php | 57 ---- .../Types/Form/SaveAndContinue.php | 34 --- .../Types/Input/CheckboxInput.php | 36 --- .../Types/Input/EntriesDateFiltersInput.php | 36 --- .../Types/Input/EntriesFieldFiltersInput.php | 54 ---- .../Types/Input/EntriesSortingInput.php | 41 --- .../Types/Union/ObjectFieldUnion.php | 78 ----- .../Types/Union/ObjectFieldValueUnion.php | 80 ----- .../WPGraphQLGravityForms.php | 184 ----------- 95 files changed, 4881 deletions(-) delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Button/Button.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/DateField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/Field.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/ListField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/NameField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PageField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TextField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/Form.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php delete mode 100644 src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php delete mode 100644 src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php diff --git a/src/class-acf.php b/src/class-acf.php index 79a7401..c925a25 100644 --- a/src/class-acf.php +++ b/src/class-acf.php @@ -117,7 +117,6 @@ private function setup_constants() { private function includes() { // Autoload Required Classes. - require_once(plugin_dir_path( __FILE__ ) . '/classes/WPGraphQLGravityForms.php'); } /** diff --git a/src/classes/WPGraphQLGravityForms/Types/Button/Button.php b/src/classes/WPGraphQLGravityForms/Types/Button/Button.php deleted file mode 100644 index 4b4dc22..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Button/Button.php +++ /dev/null @@ -1,45 +0,0 @@ - __( 'Gravity Forms button.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - // @TODO: Convert to an enum. - 'type' => [ - 'type' => 'String', - 'description' => __( 'Specifies the type of button to be displayed. Possible values: text, image.', 'wp-graphql-gravity-forms' ), - ], - 'text' => [ - 'type' => 'String', - 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), - ], - 'imageUrl' => [ - 'type' => 'String', - 'description' => __( 'Contains the URL for the image button. Only applicable when type is set to image.', 'wp-graphql-gravity-forms' ), - ], - 'conditionalLogic' => [ - 'type' => ConditionalLogic::TYPE, - 'description' => __( 'Controls when the form button should be visible based on values selected on the form.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php deleted file mode 100644 index f152849..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogic.php +++ /dev/null @@ -1,41 +0,0 @@ - __( 'Gravity Forms conditional logic.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - // TODO: convert type to enum - 'actionType' => [ - 'type' => 'String', - 'description' => __( 'The type of action the conditional logic will perform. Possible values: show, hide.', 'wp-graphql-gravity-forms' ), - ], - // TODO: convert type to enum - 'logicType' => [ - 'type' => 'String', - 'description' => __( 'Determines how to the rules should be evaluated. Possible values: any, all.', 'wp-graphql-gravity-forms' ), - ], - 'rules' => [ - 'type' => [ 'list_of' => ConditionalLogicRule::TYPE ], - 'description' => __( 'Conditional logic rules.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php b/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php deleted file mode 100644 index 594c7f3..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/ConditionalLogic/ConditionalLogicRule.php +++ /dev/null @@ -1,40 +0,0 @@ - __( 'Gravity Forms conditional logic rule.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'fieldId' => [ - 'type' => 'Integer', - 'description' => __( 'Target field Id. Field that will have it’s value compared with the value property to determine if this rule is a match.', 'wp-graphql-gravity-forms' ), - ], - // TODO: convert to enum. - 'operator' => [ - 'type' => 'String', - 'description' => __( 'Operator to be used when evaluating this rule. Possible values: is, isnot, >, <, contains, starts_with, or ends_with.', 'wp-graphql-gravity-forms' ), - ], - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value to compare with field specified by fieldId.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php b/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php deleted file mode 100644 index 0663a89..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Entry/Entry.php +++ /dev/null @@ -1,181 +0,0 @@ -entry_data_manipulator = $entry_data_manipulator; - $this->draft_entry_data_manipulator = $draft_entry_data_manipulator; - } - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register_type' ] ); - add_action( 'graphql_register_types', [ $this, 'register_field' ] ); - } - - public function register_type() { - register_graphql_object_type( self::TYPE, [ - 'description' => __( 'Gravity Forms entry.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( 'Unique global ID for the object.', 'wp-graphql-gravity-forms' ), - ], - 'entryId' => [ - 'type' => 'Integer', - 'description' => __( 'The entry ID. Returns null for draft entries.', 'wp-graphql-gravity-forms' ), - ], - 'formId' => [ - 'type' => 'Integer', - 'description' => __( 'The ID of the form that was submitted to generate this entry.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Add field to get post data. - 'postId' => [ - 'type' => 'Integer', - 'description' => __( 'For forms with Post fields, this property contains the Id of the Post that was created.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Gravity Forms stores and returns the dateCreated and dateUpdated in UTC time. - // Change the fields below to be in the blog's local time, and add new ones for - // dateCreatedUTC and dateUpdatedUTC. - 'dateCreated' => [ - 'type' => 'String', - 'description' => __( 'The date and time that the entry was created, in the format "yyyy-mm-dd hh:mi:ss" (i.e. 2010-07-15 17:26:58).', 'wp-graphql-gravity-forms' ), - ], - 'dateUpdated' => [ - 'type' => 'String', - 'description' => __( 'The date and time that the entry was updated, in the format "yyyy-mm-dd hh:mi:ss" (i.e. 2010-07-15 17:26:58).', 'wp-graphql-gravity-forms' ), - ], - 'isStarred' => [ - 'type' => 'Boolean', - 'description' => __( 'Indicates if the entry has been starred (i.e marked with a star). 1 for entries that are starred and 0 for entries that are not starred.', 'wp-graphql-gravity-forms' ), - ], - 'isRead' => [ - 'type' => 'Boolean', - 'description' => __( 'Indicates if the entry has been read. 1 for entries that are read and 0 for entries that have not been read.', 'wp-graphql-gravity-forms' ), - ], - 'ip' => [ - 'type' => 'String', - 'description' => __( 'Client IP of user who submitted the form.', 'wp-graphql-gravity-forms' ), - ], - 'sourceUrl' => [ - 'type' => 'String', - 'description' => __( 'Source URL of page that contained the form when it was submitted.', 'wp-graphql-gravity-forms' ), - ], - 'userAgent' => [ - 'type' => 'String', - 'description' => __( 'Provides the name and version of both the browser and operating system from which the entry was submitted.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Add field to get user data. - 'createdById' => [ - 'type' => 'Integer', - 'description' => __( 'ID of the user that submitted of the form if a logged in user submitted the form.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to an enum. - 'status' => [ - 'type' => 'String', - 'description' => __( 'The current status of the entry; "active", "spam", or "trash".', 'wp-graphql-gravity-forms' ), - ], - 'isDraft' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the entry is a draft.', 'wp-graphql-gravity-forms' ), - ], - 'resumeToken' => [ - 'type' => 'String', - 'description' => __( 'The resume token. Only applies to draft entries.', 'wp-graphql-gravity-forms' ), - ], - /** - * @TODO: Add support for these pricing properties that are only relevant - * when a Gravity Forms payment gateway add-on is being used: - * https://docs.gravityforms.com/entry-object/#pricing-properties - */ - ], - ] ); - } - - public function register_field() { - register_graphql_field( 'RootQuery', self::FIELD, [ - 'description' => __( 'Get a Gravity Forms entry.', 'wp-graphql-gravity-forms' ), - 'type' => self::TYPE, - 'args' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( "Unique global ID for the object. Base-64 encode a string like this, where '123' is the entry ID (or the resume token for a draft entry): '{self::TYPE}:123'.", 'wp-graphql-gravity-forms' ), - ], - ], - 'resolve' => function( $root, array $args, AppContext $context, ResolveInfo $info ) { - if ( ! current_user_can( 'gravityforms_view_entries' ) ) { - throw new UserError( __( 'Sorry, you are not allowed to view Gravity Forms entries.', 'wp-graphql-gravity-forms' ) ); - } - - $id_parts = Relay::fromGlobalId( $args['id'] ); - - if ( ! is_array( $id_parts ) || empty( $id_parts['id'] ) || empty( $id_parts['type'] ) ) { - throw new UserError( __( 'A valid global ID must be provided.', 'wp-graphql-gravity-forms' ) ); - } - - $id = sanitize_text_field( $id_parts['id'] ); - $entry = GFAPI::get_entry( $id ); - - if ( ! is_wp_error( $entry ) ) { - return $this->entry_data_manipulator->manipulate( $entry ); - } - - $draft_entry = GFFormsModel::get_draft_submission_values( $id ); - - if ( ! $draft_entry || ! is_array( $draft_entry ) ) { - throw new UserError( __( 'An entry with this ID was not found.', 'wp-graphql-gravity-forms' ) ); - } - - $submission = json_decode( $draft_entry['submission'], true ); - - if ( ! $submission ) { - throw new UserError( __( 'The submission data for this draft entry could not be read.', 'wp-graphql-gravity-forms' ) ); - } - - return $this->draft_entry_data_manipulator->manipulate( $submission['partial_entry'], $id ); - } - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php deleted file mode 100644 index ebe47d6..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryForm.php +++ /dev/null @@ -1,74 +0,0 @@ -form_data_manipulator = $form_data_manipulator; - } - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register_type' ] ); - add_action( 'graphql_register_types', [ $this, 'register_field' ] ); - } - - /** - * Register new edge type. - */ - public function register_type() { - register_graphql_type( self::TYPE, [ - 'description' => __('The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'node' => [ - 'type' => Form::TYPE, - 'description' => __( 'The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - public function register_field() { - register_graphql_field( Entry::TYPE, self::FIELD, [ - 'type' => self::TYPE, - 'description' => __( 'The Gravity Forms form associated with the entry.', 'wp-graphql-gravity-forms' ), - 'resolve' => function( array $entry ) : array { - $form = GFAPI::get_form( $entry['formId'] ); - - if ( ! $form ) { - throw new UserError( __( 'The form used to generate this entry was not found.', 'wp-graphql-gravity-forms' ) ); - } - - return [ - 'node' => $this->form_data_manipulator->manipulate( $form ), - ]; - } - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php b/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php deleted file mode 100644 index b06b764..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Entry/EntryUser.php +++ /dev/null @@ -1,64 +0,0 @@ - __('The user who created the entry.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'node' => [ - 'type' => 'User', - 'description' => __( 'The user who created the entry.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - public function register_field() { - register_graphql_field( Entry::TYPE, self::FIELD, [ - 'type' => self::TYPE, - 'description' => __( 'The user who created the entry.', 'wp-graphql-gravity-forms' ), - 'resolve' => function( array $entry ) : array { - $user = get_userdata( $entry['createdById'] ); - - if ( ! $user instanceof WP_User ) { - throw new UserError( __( 'The user who created this entry could not be found.', 'wp-graphql-gravity-forms' ) ); - } - - return [ - 'node' => new User( $user ), - ]; - } - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php b/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php deleted file mode 100644 index 77ef421..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Enum/FieldFiltersOperatorInputEnum.php +++ /dev/null @@ -1,52 +0,0 @@ -'; - const LESS_THAN = '<'; - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register' ] ); - } - - public function register() { - register_graphql_enum_type( - self::TYPE, - [ - 'description' => __( 'The operator to use for filtering.', 'harness' ), - 'values' => [ - 'IN' => [ - 'description' => __( 'Find field values that match those in the values array (default).', 'harness' ), - 'value' => self::IN, - ], - 'NOT_IN' => [ - 'description' => __( 'Find field values that do NOT match those in the values array.', 'harness' ), - 'value' => self::NOT_IN, - ], - 'CONTAINS' => [ - 'description' => __( 'Find field values that contain the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), - 'value' => self::CONTAINS, - ], - 'GREATER_THAN' => [ - 'description' => __( 'Find field values that are greater than the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), - 'value' => self::GREATER_THAN, - ], - 'LESS_THAN' => [ - 'description' => __( 'Find field values that are less than the value in the values array. Only the first value in the values array will be used; any others will be disregarded.', 'harness' ), - 'value' => self::LESS_THAN, - ], - ], - ] - ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php b/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php deleted file mode 100644 index e4eb27e..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Enum/FormStatusEnum.php +++ /dev/null @@ -1,47 +0,0 @@ - __( 'Status of forms to get. Default is ACTIVE.', 'harness' ), - 'values' => [ - self::ACTIVE => [ - 'description' => __( 'Active forms (default).', 'harness' ), - 'value' => self::ACTIVE, - ], - self::INACTIVE => [ - 'description' => __( 'Inactive forms', 'harness' ), - 'value' => self::INACTIVE, - ], - self::TRASHED => [ - 'description' => __( 'Active forms in the trash.', 'harness' ), - 'value' => self::TRASHED, - ], - self::INACTIVE_TRASHED => [ - 'description' => __( 'Inactive forms in the trash.', 'harness' ), - 'value' => self::INACTIVE_TRASHED, - ], - ], - ] - ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php b/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php deleted file mode 100644 index 0db67de..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/AddressField.php +++ /dev/null @@ -1,66 +0,0 @@ - __( 'Gravity Forms Address field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\InputsProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\LabelPlacementProperty::get(), - FieldProperty\SizeProperty::get(), - [ - // @TODO - Convert to an enum. Possible values: international, us, canadian - 'addressType' => [ - 'type' => 'String', - 'description' => __('Determines the type of address to be displayed.', 'wp-graphql-gravity-forms'), - ], - 'defaultCountry' => [ - 'type' => 'String', - 'description' => __('Contains the country that will be selected by default. Only applicable when "addressType" is set to "international".', 'wp-graphql-gravity-forms'), - ], - 'defaultProvince' => [ - 'type' => 'String', - 'description' => __('Contains the province that will be selected by default. Only applicable when "addressType" is set to "canadian".', 'wp-graphql-gravity-forms'), - ], - 'defaultState' => [ - 'type' => 'String', - 'description' => __('Contains the state that will be selected by default. Only applicable when "addressType" is set to "us".', 'wp-graphql-gravity-forms'), - ], - 'subLabelPlacement' => [ - 'type' => 'String', - 'description' => __( 'The placement of the labels for the fields (street, city, zip/postal code, etc.) within the address group. This setting controls all of the address pieces, they cannot be set individually. They may be aligned above or below the inputs. If this property is not set, the “Sub-Label Placement” setting on the Form Settings->Form Layout page is used. If no setting is specified, the default is above inputs.', 'wp-graphql-gravity-forms' ), - ], - // @TODO - add placeholders. - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php deleted file mode 100644 index 6b657e5..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/CalculationField.php +++ /dev/null @@ -1,56 +0,0 @@ - __( 'Gravity Forms Calculation field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionPlacementProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - [ - 'calculationFormula' => [ - 'type' => 'String', - 'description' => __( 'The formula to be used.', 'wp-graphql-gravity-forms' ), - ], - 'enableCalculation' => [ - 'type' => 'Boolean', - 'description' => __( 'Indicates whether the calculation use is active.', 'wp-graphql-gravity-forms '), - ], - // @TODO: Convert to an enum. - 'calculationRounding' => [ - 'type' => 'String', - 'description' => __( 'The number of decimal places the number should be rounded to. Possible values: norounding, 0, 1, 2, 3, 4.', 'wp-graphql-gravity-forms '), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php deleted file mode 100644 index cf1c5e7..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/CaptchaField.php +++ /dev/null @@ -1,67 +0,0 @@ - __( 'Gravity Forms CAPTCHA field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\ErrorMessageProperty::get(), - [ - /** - * Possible values: recaptcha, simple_captcha, math - */ - 'captchaType' => [ - 'type' => 'String', - 'description' => __('Determines the type of CAPTCHA field to be used.', 'wp-graphql-gravity-forms'), - ], - /** - * Possible values: red, white, blackglass, clean - */ - 'captchaTheme' => [ - 'type' => 'String', - 'description' => __('Determines the theme to be used for the reCAPTCHA field. Only applicable to the recaptcha captcha type.', 'wp-graphql-gravity-forms'), - ], - /** - * Possible values: small, medium, large - */ - 'simpleCaptchaSize' => [ - 'type' => 'String', - 'description' => __('Determines the CAPTCHA image size. Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), - ], - 'simpleCaptchaFontColor' => [ - 'type' => 'String', - 'description' => __('Determines the image’s font color, in HEX format (i.e. #CCCCCC). Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), - ], - 'simpleCaptchaBackgroundColor' => [ - 'type' => 'String', - 'description' => __('Determines the image’s background color, in HEX format (i.e. #CCCCCC). Only applicable to simple_captcha and math captcha types.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php deleted file mode 100644 index df40446..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/ChainedSelectField.php +++ /dev/null @@ -1,56 +0,0 @@ - __( 'Gravity Forms Chained Select field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputsProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'choices' => [ - 'type' => [ 'list_of' => FieldProperty\ChainedSelectChoiceProperty::TYPE ], - 'description' => __('Choices used to populate the dropdown field. These can be nested multiple levels deep.', 'wp-graphql-gravity-forms'), - ], - // @TODO: Convert to an enum. - 'chainedSelectsAlignment' => [ - 'type' => 'String', - 'description' => __('Alignment of the dropdown fields. Possible values: "horizontal" (in a row) or "vertical" (in a column).', 'wp-graphql-gravity-forms'), - ], - 'chainedSelectsHideInactive' => [ - 'type' => 'Boolean', - 'description' => __('Whether inactive dropdowns should be hidden.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php b/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php deleted file mode 100644 index d5358b9..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/CheckboxField.php +++ /dev/null @@ -1,52 +0,0 @@ - __( 'Gravity Forms Checkbox field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\ChoicesProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\EnableChoiceValueProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'inputs' => [ - 'type' => [ 'list_of' => FieldProperty\CheckboxInputProperty::TYPE ], - 'description' => __( 'List of inputs. Checkboxes are treated as multi-input fields, since each checkbox item is stored separately.', 'wp-graphql-gravity-forms' ), - ], - 'enableSelectAll' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the "select all" choice should be displayed.', 'wp-graphql-gravity-forms' ), - ] - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php b/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php deleted file mode 100644 index f498596..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/DateField.php +++ /dev/null @@ -1,63 +0,0 @@ - __( 'Gravity Forms Date field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get(), - [ - /** - * Possible values: Possible values: calendar, custom, none - */ - 'calendarIconType' => [ - 'type' => 'String', - 'description' => __('Determines how the date field displays it’s calendar icon.', 'wp-graphql-gravity-forms'), - ], - 'calendarIconUrl' => [ - 'type' => 'String', - 'description' => __('Contains the URL to the custom calendar icon. Only applicable when calendarIconType is set to custom.', 'wp-graphql-gravity-forms'), - ], - /** - * Possible values: mdy, dmy - */ - 'dateFormat' => [ - 'type' => 'String', - 'description' => __('Determines how the date is displayed.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php b/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php deleted file mode 100644 index 5139920..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/EmailField.php +++ /dev/null @@ -1,43 +0,0 @@ - __( 'Gravity Forms Email field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/Field.php b/src/classes/WPGraphQLGravityForms/Types/Field/Field.php deleted file mode 100644 index 332e97e..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/Field.php +++ /dev/null @@ -1,69 +0,0 @@ - [ - 'type' => 'String', - 'description' => __( 'When specified, the value of this property will be used on the admin pages instead of the label. It is useful for fields with long labels.', 'wp-graphql-gravity-forms' ), - ], - 'adminOnly' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if this field should only visible on the administration pages. A value of 1 will mark the field as admin only and will hide it from the public form. Useful for fields such as “status” that help with managing entries, but don’t apply to users filling out the form.', 'wp-graphql-gravity-forms' ), - ], - 'allowsPrepopulate' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the field’s value can be pre-populated dynamically. 1 to allow field to be pre-populated, 0 otherwise.', 'wp-graphql-gravity-forms' ), - ], - 'conditionalLogic' => [ - 'type' => ConditionalLogic::TYPE, - 'description' => __( 'Controls the visibility of the field based on values selected by the user.', 'wp-graphql-gravity-forms' ), - ], - 'cssClass' => [ - 'type' => 'String', - 'description' => __( 'String containing the custom CSS classes to be added to the
  • tag that contains the field. Useful for applying custom formatting to specific fields.', 'wp-graphql-gravity-forms' ), - ], - 'cssClassList' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Array of the custom CSS classes to be added to the
  • tag that contains the field. Useful for applying custom formatting to specific fields.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: consider changing this to fieldId so that id can be used for the global Relay ID. - 'id' => [ - 'type' => 'Integer', - 'description' => __( 'Field ID.', 'wp-graphql-gravity-forms' ), - ], - 'label' => [ - 'type' => 'String', - 'description' => __( 'Field label that will be displayed on the form and on the admin pages.', 'wp-graphql-gravity-forms' ), - ], - 'type' => [ - 'type' => 'String', - 'description' => __( 'The type of field to be displayed.', 'wp-graphql-gravity-forms' ), - ], - 'formId' => [ - 'type' => 'Integer', - 'description' => __( 'The ID of the form this field belongs to.', 'wp-graphql-gravity-forms' ), - ], - 'visibility' => [ - 'type' => 'String', - 'description' => __( 'Field visibility. Possible values: visible, hidden, or administrative.', 'wp-graphql-gravity-forms' ), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php deleted file mode 100644 index 87562c1..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChainedSelectChoiceProperty.php +++ /dev/null @@ -1,44 +0,0 @@ - __('Gravity Forms Chained Select field choice property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'text' => [ - 'type' => 'String', - 'description' => __('The text to be displayed to the user when displaying this choice.', 'wp-graphql-gravity-forms'), - ], - 'value' => [ - 'type' => 'String', - 'description' => __('The value to be stored in the database when this choice is selected.', 'wp-graphql-gravity-forms'), - ], - 'isSelected' => [ - 'type' => 'Boolean', - 'description' => __('Determines if this choice should be selected by default when displayed. The value true will select the choice, whereas false will display it unselected.', 'wp-graphql-gravity-forms'), - ], - 'choices' => [ - 'type' => [ 'list_of' => self::TYPE ], - 'description' => __('Choices used to populate the dropdown field. These can be nested multiple levels deep.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php deleted file mode 100644 index 22e3744..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/CheckboxInputProperty.php +++ /dev/null @@ -1,40 +0,0 @@ - __('Gravity Forms Chained Select field choice property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'id' => [ - 'type' => 'Float', - 'description' => __('The input id. Input Ids follow the following naming convention: “FIELDID.INPUTID” (i.e. 5.1), where FIELDID is the id of the containing field and INPUTID specifies the input field.', 'wp-graphql-gravity-forms'), - ], - 'label' => [ - 'type' => 'String', - 'description' => __('Input label.', 'wp-graphql-gravity-forms'), - ], - 'name' => [ - 'type' => 'String', - 'description' => __('When the field is configured with allowsPrepopulate set to 1, this property contains the parameter name to be used to populate this field (equivalent to the inputName property of single-input fields).', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php deleted file mode 100644 index f0809ce..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoiceProperty.php +++ /dev/null @@ -1,42 +0,0 @@ - __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'text' => [ - 'type' => 'String', - 'description' => __('The text to be displayed to the user when displaying this choice.', 'wp-graphql-gravity-forms'), - ], - 'value' => [ - 'type' => 'String', - 'description' => __('The value to be stored in the database when this choice is selected. Note: This property is only supported by the Drop Down and Post Category fields. Checkboxes and Radio fields will store the text property in the database regardless of the value property.', 'wp-graphql-gravity-forms'), - ], - 'isSelected' => [ - 'type' => 'Boolean', - 'description' => __('Determines if this choice should be selected by default when displayed. The value true will select the choice, whereas false will display it unselected.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php deleted file mode 100644 index 01bc945..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ChoicesProperty.php +++ /dev/null @@ -1,26 +0,0 @@ - [ - 'type' => [ 'list_of' => ChoiceProperty::TYPE ], - 'description' => __('Contains the available choices for the field. For instance, drop down items and checkbox items are configured with this property.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php deleted file mode 100644 index c2f4d82..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DefaultValueProperty.php +++ /dev/null @@ -1,22 +0,0 @@ - [ - 'type' => 'String', - 'description' => __( 'Contains the default value for the field. When specified, the field\'s value will be populated with the contents of this property when the form is displayed.', 'wp-graphql-gravity-forms' ), - ] - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php deleted file mode 100644 index f839d49..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionPlacementProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => 'String', - 'description' => __('The placement of the field description. The description may be placed “above” or “below” the field inputs. If the placement is not specified, then the description placement setting for the Form Layout is used.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php deleted file mode 100644 index 3ca04cf..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/DescriptionProperty.php +++ /dev/null @@ -1,19 +0,0 @@ - [ - 'type' => 'String', - 'description' => __( 'Field description.', 'wp-graphql-gravity-forms' ), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php deleted file mode 100644 index 1f2251c..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableChoiceValueProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => 'Boolean', - 'description' => __('Determines if the field (checkbox, select or radio) have choice values enabled, which allows the field to have choice values different from the labels that are displayed to the user.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php deleted file mode 100644 index fddcd37..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/EnableEnhancedUiProperty.php +++ /dev/null @@ -1,26 +0,0 @@ - [ - 'type' => 'Boolean', - 'description' => __('When set to true, the "Chosen" jQuery script will be applied to this field, enabling search capabilities to Drop Down fields and a more user-friendly interface for Multi Select fields.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php deleted file mode 100644 index 568e145..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ErrorMessageProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => 'String', - 'description' => __('Contains the message that is displayed for fields that fail validation.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php deleted file mode 100644 index 74caead..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputNameProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => 'String', - 'description' => __('Assigns a name to this field so that it can be populated dynamically via this input name. Only applicable when allowsPrepopulate is set to 1.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php deleted file mode 100644 index b4bada6..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputProperty.php +++ /dev/null @@ -1,48 +0,0 @@ - __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'id' => [ - 'type' => 'Float', - 'description' => __('The input id. Input Ids follow the following naming convention: “FIELDID.INPUTID” (i.e. 5.1), where FIELDID is the id of the containing field and INPUTID specifies the input field.', 'wp-graphql-gravity-forms'), - ], - 'label' => [ - 'type' => 'String', - 'description' => __('Input label.', 'wp-graphql-gravity-forms'), - ], - 'name' => [ - 'type' => 'String', - 'description' => __('When the field is configured with allowsPrepopulate set to 1, this property contains the parameter name to be used to populate this field (equivalent to the inputName property of single-input fields).', 'wp-graphql-gravity-forms'), - ], - 'key' => [ - 'type' => 'String', - 'description' => __('Key used to identify this input.', 'wp-graphql-gravity-forms'), - ], - 'isHidden' => [ - 'type' => 'Boolean', - 'description' => __('Whether or not this field should be hidden.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php deleted file mode 100644 index e0f0e21..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/InputsProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => [ 'list_of' => InputProperty::TYPE ], - 'description' => __('For fields with multiple inputs (i.e. Name, Address), this property contains a list of inputs. This property also applies to the checkbox field as checkboxes are treated as multi-input fields (since each checkbox item is stored separately).', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php deleted file mode 100644 index 3b6998c..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/IsRequiredProperty.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'type' => 'Boolean', - 'description' => __('Determines if the field requires the user to enter a value. 1 marks the field as required, 0 marks the field as not required. Fields marked as required will prevent the form from being submitted if the user has not entered a value in it.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php deleted file mode 100644 index d46a720..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/LabelPlacementProperty.php +++ /dev/null @@ -1,20 +0,0 @@ - [ - 'type' => 'String', - 'description' => __( 'The field label position. Empty when using the form defaults or a value of "hidden_label".', 'wp-graphql-gravity-forms' ), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php deleted file mode 100644 index 2645156..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/ListChoiceProperty.php +++ /dev/null @@ -1,38 +0,0 @@ - __('List field column labels.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'text' => [ - 'type' => 'String', - 'description' => __('The text to be displayed in the column header. Required.', 'wp-graphql-gravity-forms'), - ], - 'value' => [ - 'type' => 'String', - 'description' => __('The text to be displayed in the column header.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php deleted file mode 100644 index a8cc37e..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MaxLengthProperty.php +++ /dev/null @@ -1,23 +0,0 @@ - [ - 'type' => 'Integer', - 'description' => __('Specifies the maximum number of characters allowed in a text or textarea (paragraph) field.', 'wp-graphql-gravity-forms'), - 'resolve' => function( GF_Field $field ) : int { - return (int) $field['maxLength']; - }, - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php deleted file mode 100644 index 48de8b9..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/MultiSelectChoiceProperty.php +++ /dev/null @@ -1,42 +0,0 @@ - __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'text' => [ - 'type' => 'String', - 'description' => __('The text that is displayed.', 'wp-graphql-gravity-forms'), - ], - 'value' => [ - 'type' => 'String', - 'description' => __('The value that is used for the multi select when the form is submitted.', 'wp-graphql-gravity-forms'), - ], - 'isSelected' => [ - 'type' => 'Boolean', - 'description' => __('Indicates whether the item is selected.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php deleted file mode 100644 index ff8c2b4..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/NoDuplicatesProperty.php +++ /dev/null @@ -1,22 +0,0 @@ - [ - 'type' => 'Boolean', - 'description' => __('Determines if the field allows duplicate submissions. 1 to prevent users from submitting the same value more than once, 0 to allow duplicate values.', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php deleted file mode 100644 index 4d17651..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PasswordInputProperty.php +++ /dev/null @@ -1,46 +0,0 @@ - __('Gravity Forms input property.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'id' => [ - 'type' => 'Integer', - 'description' => __('The id of the input field.', 'wp-graphql-gravity-forms'), - ], - 'label' => [ - 'type' => 'String', - 'description' => __('The label for the input.', 'wp-graphql-gravity-forms'), - ], - 'customLabel' => [ - 'type' => 'String', - 'description' => __('The custom label for the input. When set, this is used in place of the label.', 'wp-graphql-gravity-forms'), - ], - 'placeholder' => [ - 'type' => 'String', - 'description' => __('Placeholder text to give the user a hint on how to fill out the field. This is not submitted with the form.', 'wp-graphql-gravity-forms'), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php deleted file mode 100644 index 12f210e..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/PlaceholderProperty.php +++ /dev/null @@ -1,19 +0,0 @@ - [ - 'type' => 'String', - 'description' => __( 'Field placeholder.', 'wp-graphql-gravity-forms' ), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php deleted file mode 100644 index 4b57c16..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldProperty/SizeProperty.php +++ /dev/null @@ -1,23 +0,0 @@ - [ - 'type' => 'String', - 'description' => __('Determines the size of the field when displayed on the page. Possible values are: "small", "medium", "large".', 'wp-graphql-gravity-forms'), - ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php deleted file mode 100644 index 2fedac5..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/AddressFieldValue.php +++ /dev/null @@ -1,74 +0,0 @@ - __( 'Gravity Forms address field values.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'street' => [ - 'type' => 'String', - 'description' => __( 'Street address.', 'wp-graphql-gravity-forms' ), - ], - 'lineTwo' => [ - 'type' => 'String', - 'description' => __( 'Address line two.', 'wp-graphql-gravity-forms' ), - ], - 'city' => [ - 'type' => 'String', - 'description' => __( 'City.', 'wp-graphql-gravity-forms' ), - ], - 'state' => [ - 'type' => 'String', - 'description' => __( 'State / province.', 'wp-graphql-gravity-forms' ), - ], - 'zip' => [ - 'type' => 'String', - 'description' => __( 'ZIP / postal code.', 'wp-graphql-gravity-forms' ), - ], - 'country' => [ - 'type' => 'String', - 'description' => __( 'Country.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'street' => $entry[ $field['inputs'][0]['id'] ], - 'lineTwo' => $entry[ $field['inputs'][1]['id'] ], - 'city' => $entry[ $field['inputs'][2]['id'] ], - 'state' => $entry[ $field['inputs'][3]['id'] ], - 'zip' => $entry[ $field['inputs'][4]['id'] ], - 'country' => $entry[ $field['inputs'][5]['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php deleted file mode 100644 index c64ca91..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/ChainedSelectFieldValue.php +++ /dev/null @@ -1,51 +0,0 @@ - __( 'Chained Select field values.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'values' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Field values.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field values. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field values. - */ - public static function get( array $entry, GF_Field $field ) : array { - $values = array_map( function( $input ) use ( $entry ) { - return $entry[ $input['id'] ] ?? ''; - }, $field->inputs ); - - return compact( 'values' ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php deleted file mode 100644 index 186f9da..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/CheckboxFieldValue.php +++ /dev/null @@ -1,59 +0,0 @@ - __( 'Checkbox field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - $field_input_ids = wp_list_pluck( $field->inputs, 'id' ); - $values = []; - - foreach( $entry as $input_id => $value ) { - if ( in_array( $input_id, $field_input_ids, true ) && '' !== $value ) { - $values[] = [ - 'inputId' => $input_id, - 'value' => $value, - ]; - } - } - - return compact( 'values' ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php deleted file mode 100644 index fd15859..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/DateFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Date field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php deleted file mode 100644 index 4f996c5..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/EmailFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Email field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php deleted file mode 100644 index a5683e4..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/FileUploadFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'File upload field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'url' => [ - 'type' => 'String', - 'description' => __( 'URL to the uploaded file.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'url' => isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null, - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php deleted file mode 100644 index 191a0d1..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/MultiSelectFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Multiselect field values.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'values' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Field values.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field values. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field values. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'values' => json_decode( $entry[ $field['id'] ], true ), - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php deleted file mode 100644 index 171a50a..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NameFieldValue.php +++ /dev/null @@ -1,69 +0,0 @@ - __( 'Name field values.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'prefix' => [ - 'type' => 'String', - 'description' => __( 'Prefix, such as Mr., Mrs. etc.', 'wp-graphql-gravity-forms' ), - ], - 'first' => [ - 'type' => 'String', - 'description' => __( 'First name.', 'wp-graphql-gravity-forms' ), - ], - 'middle' => [ - 'type' => 'String', - 'description' => __( 'Middle name.', 'wp-graphql-gravity-forms' ), - ], - 'last' => [ - 'type' => 'String', - 'description' => __( 'Last name.', 'wp-graphql-gravity-forms' ), - ], - 'suffix' => [ - 'type' => 'String', - 'description' => __( 'Suffix, such as Sr., Jr. etc.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'prefix' => $entry[ $field['inputs'][0]['id'] ], - 'first' => $entry[ $field['inputs'][1]['id'] ], - 'middle' => $entry[ $field['inputs'][2]['id'] ], - 'last' => $entry[ $field['inputs'][3]['id'] ], - 'suffix' => $entry[ $field['inputs'][4]['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php deleted file mode 100644 index c7a7a3e..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/NumberFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Number field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php deleted file mode 100644 index 2d65ad0..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/PhoneFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Phone field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php deleted file mode 100644 index 1d2d587..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/RadioFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Radio field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - $value = isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null; - - return [ 'value' => $value ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php deleted file mode 100644 index cf1fdf2..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SelectFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Select field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php deleted file mode 100644 index 2f5d44f..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/SignatureFieldValue.php +++ /dev/null @@ -1,53 +0,0 @@ - __( 'Signature field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'url' => [ - 'type' => 'String', - 'description' => __( 'The URL to the signature image.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - if ( ! function_exists( 'gf_signature' ) ) { - return []; - } - - return [ - 'url' => gf_signature()->get_signature_url( $entry[ $field['id'] ] ), - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php deleted file mode 100644 index 7225be0..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextAreaFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Textarea field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - $value = isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null; - - return [ 'value' => $value ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php deleted file mode 100644 index 9ca48a2..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TextFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Text field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => isset( $entry[ $field['id'] ] ) ? (string) $entry[ $field['id'] ] : null, - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php deleted file mode 100644 index 83a5ab6..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/TimeFieldValue.php +++ /dev/null @@ -1,71 +0,0 @@ - __( 'Time field values.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'displayValue' => [ - 'type' => 'String', - 'description' => __( 'The full display value. Example: "08:25 am".', 'wp-graphql-gravity-forms' ), - ], - 'hours' => [ - 'type' => 'String', - 'description' => __( 'The hours, in this format: hh.', 'wp-graphql-gravity-forms' ), - ], - 'minutes' => [ - 'type' => 'String', - 'description' => __( 'The minutes, in this format: mm.', 'wp-graphql-gravity-forms' ), - ], - 'amPm' => [ - 'type' => 'String', - 'description' => __( 'AM or PM.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - $display_value = $entry[ $field['id'] ]; - $parts_by_colon = explode( ':', $display_value ); - $hours = $parts_by_colon[0] ?? ''; - $parts_by_space = explode( ' ', $display_value ); - $am_pm = $parts_by_space[1] ?? ''; - $minutes = rtrim( ltrim( $display_value, "{$hours}:" ), " {$am_pm}" ); - - return [ - 'displayValue' => $display_value, - 'hours' => $hours, - 'minutes' => $minutes, - 'amPm' => $am_pm, - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php b/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php deleted file mode 100644 index 05efa1a..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FieldValue/WebsiteFieldValue.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Website field value.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - /** - * Get the field value. - * - * @param array $entry Gravity Forms entry. - * @param GF_Field $field Gravity Forms field. - * - * @return array Entry field value. - */ - public static function get( array $entry, GF_Field $field ) : array { - return [ - 'value' => (string) $entry[ $field['id'] ], - ]; - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php b/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php deleted file mode 100644 index ca46c63..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/FileUploadField.php +++ /dev/null @@ -1,40 +0,0 @@ - __( 'Gravity Forms File Upload field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php b/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php deleted file mode 100644 index c8faf9d..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/HiddenField.php +++ /dev/null @@ -1,40 +0,0 @@ - __( 'Gravity Forms Hidden field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php b/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php deleted file mode 100644 index b934f95..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/HtmlField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms HTML field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\InputNameProperty::get(), - [ - 'content' => [ - 'type' => 'String', - 'description' => __( 'Content of an HTML block field to be displayed on the form.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php b/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php deleted file mode 100644 index e836f63..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/ListField.php +++ /dev/null @@ -1,67 +0,0 @@ - __( 'Gravity Forms List field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionPlacementProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\LabelPlacementProperty::get(), - [ - 'addIconUrl' => [ - 'type' => 'String', - 'description' => __('The URL of the image to be used for the add row button.', 'wp-graphql-gravity-forms'), - ], - 'choices' => [ - 'type' => [ 'list_of' => FieldProperty\ListChoiceProperty::TYPE ], - 'description' => __('The column labels. Only used when enableColumns is true.', 'wp-graphql-gravity-forms'), - ], - 'deleteIconUrl' => [ - 'type' => 'String', - 'description' => __('The URL of the image to be used for the delete row button.', 'wp-graphql-gravity-forms'), - ], - 'enableColumns' => [ - 'type' => 'Boolean', - 'description' => __('Determines if the field should use multiple columns. Default is false.', 'wp-graphql-gravity-forms'), - ], - 'maxRows' => [ - 'type' => 'Integer', - 'description' => __( 'The maximum number of rows the user can add to the field.', 'wp-graphql-gravity-forms' ), - ], - 'pageNumber' => [ - 'type' => 'Integer', - 'description' => __( 'The form page this field is located on. Default is 1.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php deleted file mode 100644 index 8e722c0..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/MultiSelectField.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Gravity Forms Multi-Select field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionPlacementProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\EnableChoiceValueProperty::get(), - FieldProperty\EnableEnhancedUiProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'choices' => [ - 'type' => [ 'list_of' => FieldProperty\MultiSelectChoiceProperty::TYPE ], - 'description' => __('The individual properties for each item in the multi-select.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php b/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php deleted file mode 100644 index a8fdb82..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/NameField.php +++ /dev/null @@ -1,51 +0,0 @@ - __( 'Gravity Forms Name field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\InputsProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - /** - * Possible values: normal, extended, simple - */ - 'nameFormat' => [ - 'type' => 'String', - 'description' => __('Determines the format of the name field.', 'wp-graphql-gravity-forms'), - ], - // @TODO: Add placeholders. - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php b/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php deleted file mode 100644 index d8d0988..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/NumberField.php +++ /dev/null @@ -1,60 +0,0 @@ - __( 'Gravity Forms Number field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get(), - [ - /** - * Possible values: decimal_dot (9,999.99), decimal_comma (9.999,99), currency. - */ - 'numberFormat' => [ - 'type' => 'String', - 'description' => __( 'Specifies the format allowed for the number field.', 'wp-graphql-gravity-forms' ), - ], - 'rangeMin' => [ - 'type' => 'Float', - 'description' => __( 'Minimum allowed value for a number field. Values lower than the number specified by this property will cause the field to fail validation.', 'wp-graphql-gravity-forms' ), - ], - 'rangeMax' => [ - 'type' => 'Float', - 'description' => __( 'Maximum allowed value for a number field. Values higher than the number specified by this property will cause the field to fail validation.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php deleted file mode 100644 index 92f7470..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PageField.php +++ /dev/null @@ -1,53 +0,0 @@ - __( 'Gravity Forms Page field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - [ - 'displayOnly' => [ - 'type' => 'Boolean', - 'description' => __('Indicates the field is only displayed and its contents are not submitted with the form/saved with the entry. This is set to true.', 'wp-graphql-gravity-forms'), - ], - 'nextButton' => [ - 'type' => Button::TYPE, - 'description' => __('An array containing the the individual properties for the "Next" button.', 'wp-graphql-gravity-forms'), - ], - 'pageNumber' => [ - 'type' => 'Integer', - 'description' => __('The page number of the current page.', 'wp-graphql-gravity-forms'), - ], - 'previousButton' => [ - 'type' => Button::TYPE, - 'description' => __('An array containing the the individual properties for the "Previous" button.', 'wp-graphql-gravity-forms'), - ], - ] - ) - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php deleted file mode 100644 index abd6385..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PasswordField.php +++ /dev/null @@ -1,55 +0,0 @@ - __( 'Gravity Forms Password field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionPlacementProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\PlaceholderProperty::get(), - [ - 'inputs' => [ - 'type' => [ 'list_of' => FieldProperty\PasswordInputProperty::TYPE ], - 'description' => __('Individual properties for each element of the password field.', 'wp-graphql-gravity-forms'), - ], - // @TODO: Convert to an enum. - 'minPasswordStrength' => [ - 'type' => 'String', - 'description' => __('Indicates how strong the password should be. The possible values are: short, bad, good, strong.', 'wp-graphql-gravity-forms'), - ], - 'passwordStrengthEnabled' => [ - 'type' => 'Boolean', - 'description' => __('Indicates whether the field displays the password strength indicator.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php deleted file mode 100644 index 408e673..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PhoneField.php +++ /dev/null @@ -1,52 +0,0 @@ - __( 'Gravity Forms Phone field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get(), - [ - /** - * Possible values: standard, international - */ - 'phoneFormat' => [ - 'type' => 'String', - 'description' => __('Determines the allowed format for phones. If the phone value does not conform with the specified format, the field will fail validation.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php deleted file mode 100644 index 1f70b70..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostCategoryField.php +++ /dev/null @@ -1,47 +0,0 @@ - __( 'Gravity Forms Post Category field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\ChoicesProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'displayAllCategories' => [ - 'type' => 'Boolean', - 'description' => __('Determines if all categories should be displayed on the Post Category drop down. 1 to display all categories, 0 otherwise. If this property is set to 1 (display all categories), the Post Category drop down will display the categories hierarchically.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php deleted file mode 100644 index ec87e3c..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostContentField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms Post Content field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php deleted file mode 100644 index f78c1fa..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostCustomField.php +++ /dev/null @@ -1,53 +0,0 @@ - __( 'Gravity Forms Post Custom Field field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'postCustomFieldName' => [ - 'type' => 'String', - 'description' => __('The name of the Post Custom Field that the submitted value should be assigned to.', 'wp-graphql-gravity-forms'), - ], - 'inputType' => [ - 'type' => 'String', - 'description' => __('Contains a field type and allows a field type to be displayed as another field type. A good example is the Post Custom Field, that can be displayed as various different types of fields.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php deleted file mode 100644 index 92e2282..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostExcerptField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms Post Excerpt field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php deleted file mode 100644 index 78b9330..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostImageField.php +++ /dev/null @@ -1,54 +0,0 @@ - __( 'Gravity Forms Post Image field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'displayCaption' => [ - 'type' => 'Boolean', - 'description' => __('Controls the visibility of the caption metadata for Post Image fields. 1 will display the caption field, 0 will hide it.', 'wp-graphql-gravity-forms'), - ], - 'displayDescription' => [ - 'type' => 'Boolean', - 'description' => __('Controls the visibility of the description metadata for Post Image fields. 1 will display the description field, 0 will hide it.', 'wp-graphql-gravity-forms'), - ], - 'displayTitle' => [ - 'type' => 'Boolean', - 'description' => __('Controls the visibility of the title metadata for Post Image fields. 1 will display the title field, 0 will hide it.', 'wp-graphql-gravity-forms'), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php deleted file mode 100644 index 4928a22..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostTagsField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms Post Tags field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php b/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php deleted file mode 100644 index f86c5ec..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/PostTitleField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms Post Title field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php b/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php deleted file mode 100644 index 1f0b525..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/RadioField.php +++ /dev/null @@ -1,49 +0,0 @@ - __( 'Gravity Forms Radio field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\ChoicesProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\EnableChoiceValueProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'enableOtherChoice' => [ - 'type' => 'Boolean', - 'description' => __( 'Indicates whether the \'Enable "other" choice\' option is checked in the editor.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php deleted file mode 100644 index 7147111..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/SectionField.php +++ /dev/null @@ -1,34 +0,0 @@ - __( 'Gravity Forms Section field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php deleted file mode 100644 index 7d227e2..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/SelectField.php +++ /dev/null @@ -1,45 +0,0 @@ - __( 'Gravity Forms Select field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\ChoicesProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\EnableChoiceValueProperty::get(), - FieldProperty\EnableEnhancedUiProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php b/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php deleted file mode 100644 index 7fcffed..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/SignatureField.php +++ /dev/null @@ -1,71 +0,0 @@ - __( 'Gravity Forms Signature field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\IsRequiredProperty::get(), - [ - 'penSize' => [ - 'type' => 'Integer', - 'description' => __( 'Size of the pen cursor.', 'wp-graphql-gravity-forms' ), - ], - 'boxWidth' => [ - 'type' => 'Integer', - 'description' => __( 'Width of the signature field in pixels.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to an enum. - 'borderWidth' => [ - 'type' => 'String', - 'description' => __( 'Width of the border around the signature area. Possible values are: 0 (none), 1 (small), 2 (medium) or 3 (large).', 'wp-graphql-gravity-forms' ), - ], - 'backgroundColor' => [ - 'type' => 'String', - 'description' => __( 'Color to be used for the background of the signature area. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), - ], - 'borderColor' => [ - 'type' => 'String', - 'description' => __( 'Color to be used for the border around the signature area. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to an enum. - 'borderStyle' => [ - 'type' => 'String', - 'description' => __( 'Border style to be used around the signature area. Possible values: dotted, dashed, groove, ridge, inset, outset, double, solid.', 'wp-graphql-gravity-forms' ), - ], - 'penColor' => [ - 'type' => 'String', - 'description' => __( 'Color of the pen to be used for the signature. Can be any valid CSS color value.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php deleted file mode 100644 index 0d77588..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/TextAreaField.php +++ /dev/null @@ -1,44 +0,0 @@ - __( 'Gravity Forms Textarea (Paragraph Text) field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\MaxLengthProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php deleted file mode 100644 index 944b9b2..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/TextField.php +++ /dev/null @@ -1,50 +0,0 @@ - __( 'Gravity Forms Single Line Text field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\MaxLengthProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get(), - [ - 'enablePasswordInput' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if a text field input tag should be created with a "password" type.', 'wp-graphql-gravity-forms' ), - ], - ] - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php b/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php deleted file mode 100644 index 5af9b9f..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/TimeField.php +++ /dev/null @@ -1,42 +0,0 @@ - __( 'Gravity Forms Time field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\SizeProperty::get() - // @TODO: Add placeholders. - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php b/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php deleted file mode 100644 index accfca9..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Field/WebsiteField.php +++ /dev/null @@ -1,43 +0,0 @@ - __( 'Gravity Forms Website field.', 'wp-graphql-gravity-forms' ), - 'fields' => array_merge( - $this->get_global_properties(), - FieldProperty\DefaultValueProperty::get(), - FieldProperty\DescriptionProperty::get(), - FieldProperty\ErrorMessageProperty::get(), - FieldProperty\InputNameProperty::get(), - FieldProperty\IsRequiredProperty::get(), - FieldProperty\NoDuplicatesProperty::get(), - FieldProperty\PlaceholderProperty::get(), - FieldProperty\SizeProperty::get() - ), - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php b/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php deleted file mode 100644 index 6dca51f..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/FieldError/FieldError.php +++ /dev/null @@ -1,29 +0,0 @@ - __( 'Field error.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'message' => [ - 'type' => 'String', - 'description' => __( 'Error message.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/Form.php b/src/classes/WPGraphQLGravityForms/Types/Form/Form.php deleted file mode 100644 index 6bf5480..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/Form.php +++ /dev/null @@ -1,285 +0,0 @@ -form_data_manipulator = $form_data_manipulator; - } - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register_type' ] ); - add_action( 'graphql_register_types', [ $this, 'register_field' ] ); - } - - public function register_type() { - register_graphql_object_type( self::TYPE, [ - 'description' => __( 'Gravity Forms form.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( 'Unique global ID for the object.', 'wp-graphql-gravity-forms' ), - ], - 'formId' => [ - 'type' => 'Int', - 'description' => __( 'Form ID.', 'wp-graphql-gravity-forms' ), - ], - 'title' => [ - 'type' => 'String', - 'description' => __( 'Form title.', 'wp-graphql-gravity-forms' ), - ], - 'description' => [ - 'type' => 'String', - 'description' => __( 'Form description.', 'wp-graphql-gravity-forms' ), - ], - // @TODO - Convert to enum. Possible values: top_label, left_label, right_label - 'labelPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-gravity-forms' ), - ], - // @TODO - Convert to enum. Possible values: above, below - 'descriptionPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-gravity-forms' ), - ], - 'button' => [ - 'type' => Button::TYPE, - 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-gravity-forms' ), - ], - 'useCurrentUserAsAuthor' => [ - 'type' => 'Boolean', - 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-gravity-forms' ), - ], - 'postContentTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-gravity-forms' ), - ], - 'postTitleTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-gravity-forms' ), - ], - 'postTitleTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-gravity-forms' ), - ], - 'postContentTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-gravity-forms' ), - ], - 'lastPageButton' => [ - 'type' => Button::TYPE, - 'description' => __( 'Last page button data.', 'wp-graphql-gravity-forms' ), - ], - 'pagination' => [ - 'type' => FormPagination::TYPE, - 'description' => __( 'Pagination data.', 'wp-graphql-gravity-forms' ), - ], - 'firstPageCssClass' => [ - 'type' => 'String', - 'description' => __( 'CSS class for the first page.', 'wp-graphql-gravity-forms' ), - ], - 'postAuthor' => [ - 'type' => 'Int', - 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-gravity-forms' ), - ], - 'postCategory' => [ - 'type' => 'Int', - 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-gravity-forms' ), - ], - 'postFormat' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-gravity-forms' ), - ], - 'postStatus' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to an enum. https://docs.gravityforms.com/gf_field_name/ - 'subLabelPlacement' => [ - 'type' => 'String', - 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-gravity-forms' ), - ], - 'cssClass' => [ - 'type' => 'String', - 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-gravity-forms' ), - ], - 'cssClassList' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-gravity-forms' ), - ], - 'enableHoneypot' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-gravity-forms' ), - ], - 'enableAnimation' => [ - 'type' => 'Boolean', - 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-gravity-forms' ), - ], - 'save' => [ - 'type' => SaveAndContinue::TYPE, - 'description' => __( '"Save and Continue" data.', 'wp-graphql-gravity-forms' ), - ], - 'limitEntries' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-gravity-forms' ), - ], - 'limitEntriesCount' => [ - 'type' => 'Int', - 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to an enum. - 'limitEntriesPeriod' => [ - 'type' => 'String', - 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-gravity-forms' ), - ], - 'limitEntriesMessage' => [ - 'type' => 'String', - 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleForm' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleStart' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleStartHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleStartMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleStartAmpm' => [ - 'type' => 'String', - 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-gravity-forms' ), - ], - 'scheduleEnd' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleEndHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleEndMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleEndAmpm' => [ - 'type' => 'String', - 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-gravity-forms' ), - ], - 'schedulePendingMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-gravity-forms' ), - ], - 'scheduleMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-gravity-forms' ), - ], - 'requireLogin' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-gravity-forms' ), - ], - 'requireLoginMessage' => [ - 'type' => 'String', - 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-gravity-forms' ), - ], - 'notifications' => [ - 'type' => [ 'list_of' => FormNotification::TYPE ], - 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), - ], - 'confirmations' => [ - 'type' => [ 'list_of' => FormConfirmation::TYPE ], - 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-gravity-forms' ), - ], - 'nextFieldId' => [ - 'type' => 'Int', - 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-gravity-forms' ), - ], - 'isActive' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is active.', 'wp-graphql-gravity-forms' ), - ], - 'dateCreated' => [ - 'type' => 'String', - 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-gravity-forms' ), - ], - 'isTrash' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } - - public function register_field() { - register_graphql_field( 'RootQuery', self::FIELD, [ - 'description' => __( 'Get a Gravity Forms form.', 'wp-graphql-gravity-forms' ), - 'type' => self::TYPE, - 'args' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( "Unique global ID for the object. Base-64 encode a string like this, where '123' is the form ID: '{self::TYPE}:123'.", 'wp-graphql-gravity-forms' ), - ], - ], - 'resolve' => function( $root, array $args ) : array { - $id_parts = Relay::fromGlobalId( $args['id'] ); - - if ( ! is_array( $id_parts ) || empty( $id_parts['id'] ) || empty( $id_parts['type'] ) ) { - throw new UserError( __( 'A valid global ID must be provided.', 'wp-graphql-gravity-forms' ) ); - } - - $form_raw = GFAPI::get_form( $id_parts['id'] ); - - if ( ! $form_raw ) { - throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-gravity-forms' ) ); - } - - $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); - - /** - * Provides the ability to manipulate the form data before it is sent to the - * client. This hook is somewhat similar to Gravity Forms' gform_pre_render hook - * and can be used for dynamic field input population, among other things. - * - * @param array $form Form meta array. - */ - return apply_filters( 'wp_graphql_gf_form_object', $form ); - } - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php deleted file mode 100644 index c3a06b4..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/FormConfirmation.php +++ /dev/null @@ -1,59 +0,0 @@ - __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'id' => [ - 'type' => 'String', - 'description' => __( 'ID.', 'wp-graphql-gravity-forms' ), - ], - 'name' => [ - 'type' => 'String', - 'description' => __( 'Name.', 'wp-graphql-gravity-forms' ), - ], - 'isDefault' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether this is the default confirmation.', 'wp-graphql-gravity-forms' ), - ], - 'type' => [ - 'type' => 'String', - 'description' => __( 'Determines the type of confirmation to be used. Possible values: message, page, redirect.', 'wp-graphql-gravity-forms' ), - ], - 'message' => [ - 'type' => 'String', - 'description' => __( 'Contains the confirmation message that will be displayed. Only applicable when type is set to message.', 'wp-graphql-gravity-forms' ), - ], - 'url' => [ - 'type' => 'String', - 'description' => __( 'Contains the URL that the browser will be redirected to. Only applicable when type is set to redirect.', 'wp-graphql-gravity-forms' ), - ], - 'pageId' => [ - 'type' => 'Integer', - 'description' => __( 'Contains the Id of the WordPress page that the browser will be redirected to. Only applicable when type is set to page.', 'wp-graphql-gravity-forms' ), - ], - 'queryString' => [ - 'type' => 'String', - 'description' => __( 'Contains the query string to be appended to the redirection url. Only applicable when type is set to redirect.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php deleted file mode 100644 index 76515c5..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotification.php +++ /dev/null @@ -1,96 +0,0 @@ - __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'isActive' => [ - 'type' => 'Boolean', - 'description' => __( 'Is the notification active or inactive. The default is true (active).', 'wp-graphql-gravity-forms' ), - ], - 'id' => [ - 'type' => 'String', - 'description' => __( 'The notification ID. A 13 character unique ID.', 'wp-graphql-gravity-forms' ), - ], - 'name' => [ - 'type' => 'String', - 'description' => __( 'The notification name.', 'wp-graphql-gravity-forms' ), - ], - 'service' => [ - 'type' => 'String', - 'description' => __( 'The name of the service to be used when sending this notification. Default is wordpress.', 'wp-graphql-gravity-forms' ), - ], - 'event' => [ - 'type' => 'String', - 'description' => __( 'The notification event. Default is form_submission.', 'wp-graphql-gravity-forms' ), - ], - 'to' => [ - 'type' => 'String', - 'description' => __( 'The ID of an email field, an email address or merge tag to be used as the email to address.', 'wp-graphql-gravity-forms' ), - ], - 'toType' => [ - 'type' => 'String', - 'description' => __( 'Identifies what to use for the notification to. Possible values: email, field, routing or hidden.', 'wp-graphql-gravity-forms' ), - ], - 'bcc' => [ - 'type' => 'String', - 'description' => __( 'The email or merge tags to be used as the email bcc address.', 'wp-graphql-gravity-forms' ), - ], - 'subject' => [ - 'type' => 'String', - 'description' => __( 'The email subject line. Merge tags supported.', 'wp-graphql-gravity-forms' ), - ], - 'message' => [ - 'type' => 'String', - 'description' => __( 'The email body/content. Merge tags supported.', 'wp-graphql-gravity-forms' ), - ], - 'from' => [ - 'type' => 'String', - 'description' => __( 'The email or merge tag to be used as the email from address.', 'wp-graphql-gravity-forms' ), - ], - 'fromName' => [ - 'type' => 'String', - 'description' => __( 'The text or merge tag to be used as the email from name.', 'wp-graphql-gravity-forms' ), - ], - 'replyTo' => [ - 'type' => 'String', - 'description' => __( 'The email or merge tags to be used as the email reply to address.', 'wp-graphql-gravity-forms' ), - ], - 'routing' => [ - 'type' => [ 'list_of' => FormNotificationRouting::TYPE ], - 'description' => __( 'Routing rules.', 'wp-graphql-gravity-forms' ), - ], - 'conditionalLogic' => [ - 'type' => ConditionalLogic::TYPE, - 'description' => __( 'An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.', 'wp-graphql-gravity-forms' ), - ], - 'disableAutoformat' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the email message should be formatted so that paragraphs are automatically added for new lines. Default is false (auto-formatting enabled).', 'wp-graphql-gravity-forms' ), - ], - 'enableAttachments' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if files uploaded on the form should be included when the notification is sent.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php deleted file mode 100644 index 915dbcd..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/FormNotificationRouting.php +++ /dev/null @@ -1,44 +0,0 @@ - __( 'Properties for all the email notifications which exist for a form.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'fieldId' => [ - 'type' => 'String', - 'description' => __( 'Target field ID. The field that will have it’s value compared with the value property to determine if this rule is a match.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: convert to an enum. - 'operator' => [ - 'type' => 'String', - 'description' => __( 'Operator to be used when evaluating this rule. Possible values: is, isnot, >, <, contains, starts_with, or ends_with.', 'wp-graphql-gravity-forms' ), - ], - 'value' => [ - 'type' => 'String', - 'description' => __( 'The value to compare with the field specified by fieldId.', 'wp-graphql-gravity-forms' ), - ], - 'email' => [ - 'type' => 'String', - 'description' => __( 'The email or merge tag to be used as the email To address if this rule is a match.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php b/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php deleted file mode 100644 index f25e784..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/FormPagination.php +++ /dev/null @@ -1,57 +0,0 @@ - __( 'Gravity Forms form pagination data.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - // @TODO - convert to enum - 'type' => [ - 'type' => 'String', - 'description' => __( 'Type of progress indicator. Possible values are: percentage, steps or none.', 'wp-graphql-gravity-forms' ), - ], - 'pages' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Names of the form\'s pages.', 'wp-graphql-gravity-forms' ), - ], - // @TODO - convert to enum - 'style' => [ - 'type' => 'String', - 'description' => __( 'Style of progress bar. Possible values are: blue, gray, green, orange, red or custom.', 'wp-graphql-gravity-forms' ), - ], - 'backgroundColor' => [ - 'type' => 'String', - 'description' => __( 'Progress bar background color. Can be any CSS color value. Only applies when "style" is set to "custom".', 'wp-graphql-gravity-forms' ), - ], - 'color' => [ - 'type' => 'String', - 'description' => __( 'Progress bar text color. Can be any CSS color value. Only applies when "style" is set to "custom".', 'wp-graphql-gravity-forms' ), - ], - 'displayProgressbarOnConfirmation' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the confirmation bar should be displayed with the confirmation text.', 'wp-graphql-gravity-forms' ), - ], - 'progressbarCompletionText' => [ - 'type' => 'String', - 'description' => __( 'The confirmation text to display once the end of the progress bar has been reached. Only applies when displayProgressbarOnConfirmation is set to true.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php b/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php deleted file mode 100644 index 3f6f704..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Form/SaveAndContinue.php +++ /dev/null @@ -1,34 +0,0 @@ - __( 'Gravity Forms form Save and Continue data.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'enabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the Save And Continue feature is enabled.', 'wp-graphql-gravity-forms' ), - ], - 'button' => [ - 'type' => Button::TYPE, - 'description' => __( 'Contains the button text. Only applicable when type is set to text.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php deleted file mode 100644 index 167b78d..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Input/CheckboxInput.php +++ /dev/null @@ -1,36 +0,0 @@ - __( 'Input fields for a single checkbox.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'inputId' => [ - 'type' => 'Float', - 'description' => __( 'Input ID.', 'wp-graphql-gravity-forms' ), - ], - 'value' => [ - 'type' => 'String', - 'description' => __( 'Input value', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php deleted file mode 100644 index 44184bd..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesDateFiltersInput.php +++ /dev/null @@ -1,36 +0,0 @@ - __('Date Filters input fields for Entries queries.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'startDate' => [ - 'type' => 'String', - 'description' => __( 'Start date in Y-m-d H:i:s format.', 'wp-graphql-gravity-forms' ), - ], - 'endDate' => [ - 'type' => 'String', - 'description' => __( 'End date in Y-m-d H:i:s format.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php deleted file mode 100644 index 44f1e7b..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesFieldFiltersInput.php +++ /dev/null @@ -1,54 +0,0 @@ - __( 'Field Filters input fields for Entries queries.', 'wp-graphql-gravity-forms' ), - 'fields' => [ - 'key' => [ - 'type' => 'String', - 'description' => __( 'The ID of the field to filter by. Use "0" to search all keys. You can also use the names of the columns in Gravity Forms\' database table for entries, such as "date_created", "is_read, "created_by", etc.', 'wp-graphql-gravity-forms' ), - ], - 'operator' => [ - 'type' => FieldFiltersOperatorInputEnum::TYPE, - 'description' => __( 'The operator to use for filtering.', 'wp-graphql-gravity-forms' ), - ], - // @TODO - Is there a cleaner way to do this? Values can be any of these types. - 'stringValues' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'The field value(s) to filter by. Must be string values. If using this field, do not also use intValues, floatValues or boolValues.', 'wp-graphql-gravity-forms' ), - ], - 'intValues' => [ - 'type' => [ 'list_of' => 'Int' ], - 'description' => __( 'The field value(s) to filter by. Must be integer values. If using this field, do not also use stringValues, floatValues or boolValues.', 'wp-graphql-gravity-forms' ), - ], - 'floatValues' => [ - 'type' => [ 'list_of' => 'Float' ], - 'description' => __( 'The field value(s) to filter by. Must be float values. If using this field, do not also use stringValues, intValues or boolValues.', 'wp-graphql-gravity-forms' ), - ], - 'boolValues' => [ - 'type' => [ 'list_of' => 'Boolean' ], - 'description' => __( 'The field value(s) to filter by. Must be boolean values. If using this field, do not also use stringValues, intValues or floatValues.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php b/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php deleted file mode 100644 index 7328595..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Input/EntriesSortingInput.php +++ /dev/null @@ -1,41 +0,0 @@ - __('Sorting input fields for Entries queries.', 'wp-graphql-gravity-forms'), - 'fields' => [ - 'key' => [ - 'type' => 'String', - 'description' => __( 'The key of the field to sort by.', 'wp-graphql-gravity-forms' ), - ], - // @TODO: Convert to enum. - 'direction' => [ - 'type' => 'String', - 'description' => __( 'The sorting direction. Possible values: DESC for descending (default), or ASC for ascending.', 'wp-graphql-gravity-forms' ), - ], - 'isNumeric' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the sorting field\'s values are numeric.', 'wp-graphql-gravity-forms' ), - ], - ], - ] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php deleted file mode 100644 index 1dd06b1..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldUnion.php +++ /dev/null @@ -1,78 +0,0 @@ -instances = $instances; - } - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register_type' ], 11 ); - } - - public function register_type( TypeRegistry $type_registry ) { - $field_mappings = $this->get_field_type_mappings(); - - register_graphql_union_type( self::TYPE, [ - 'typeNames' => array_values( $field_mappings ), - 'resolveType' => function( GF_Field $field ) use ( $field_mappings, $type_registry ) { - if ( isset( $field_mappings[ $field['type'] ] ) ) { - return $type_registry->get_type( $field_mappings[ $field['type'] ] ); - } - - return null; - }, - ] ); - } - - /** - * Get mappings from the field types registered in Gravity Forms - * to the corresponding field types registered in WPGraphQL. - * Example: [ 'textarea' => 'TextAreaField' ] - * - * @return array Field type mappings. - */ - private function get_field_type_mappings() : array { - $fields = array_filter( $this->instances, function( $instance ) { - return $instance instanceof Field; - } ); - - /** - * Filter for adding custom field class instances to be used by this union's resolver. - * - * @param array $fields Gravity Forms field class instances. - */ - $fields = apply_filters( 'wp_graphql_gf_form_field_instances', $fields ); - - return array_reduce( $fields, function( $mappings, $field ) { - $mappings[ $field::GF_TYPE ] = $field::TYPE; - - return $mappings; - }, [] ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php b/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php deleted file mode 100644 index a1219e3..0000000 --- a/src/classes/WPGraphQLGravityForms/Types/Union/ObjectFieldValueUnion.php +++ /dev/null @@ -1,80 +0,0 @@ -instances = $instances; - } - - public function register_hooks() { - add_action( 'graphql_register_types', [ $this, 'register_type' ], 11 ); - } - - public function register_type( $type_registry ) { - $field_value_types = $this->get_field_value_types(); - register_graphql_union_type( self::TYPE, [ - 'typeNames' => array_unique( array_values( $field_value_types ) ), - 'resolveType' => function( $object ) use ( $field_value_types, $type_registry ) { - if ( isset( $field_value_types[ $object['type'] ] ) ) { - return $type_registry->get_type( $field_value_types[ $object['type'] ] ); - } - - return null; - }, - ] ); - } - - - /** - * Get field types and their related field value types. - * Example: [ 'AddressField' => 'AddressFieldValues' ] - * - * @return array Field value types. - */ - private function get_field_value_types() : array { - $fields_with_value_types = array_filter( $this->instances, function( $instance ) { - return $instance instanceof Field && $this->does_field_have_value_type( $instance ); - } ); - - return array_reduce( $fields_with_value_types, function( $value_types, $field ) { - $value_types[ $field::TYPE ] = $field::TYPE . 'Value'; - - return $value_types; - }, [] ); - } - - /** - * @param Field $field Gravity Forms field. - * - * @return bool Whether $field has a corresponding field value type. - */ - private function does_field_have_value_type( Field $field ) : bool { - return class_exists( 'WPGraphQLGravityForms\Types\Field\FieldValue\\' . $field::TYPE . 'Value' ); - } -} diff --git a/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php b/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php deleted file mode 100644 index d234902..0000000 --- a/src/classes/WPGraphQLGravityForms/WPGraphQLGravityForms.php +++ /dev/null @@ -1,184 +0,0 @@ -create_instances(); - $this->register_hooks(); - } - - private function create_instances() { - // Data manipulators - $this->instances['fields_data_manipulator'] = new DataManipulators\FieldsDataManipulator(); - $this->instances['form_data_manipulator'] = new DataManipulators\FormDataManipulator( $this->instances['fields_data_manipulator'] ); - $this->instances['entry_data_manipulator'] = new DataManipulators\EntryDataManipulator(); - $this->instances['draft_entry_data_manipulator'] = new DataManipulators\DraftEntryDataManipulator( $this->instances['entry_data_manipulator'] ); - - // Buttons - $this->instances['button'] = new Button(); - - // Conditional Logic - $this->instances['conditional_logic'] = new ConditionalLogic\ConditionalLogic(); - $this->instances['conditional_logic_rule'] = new ConditionalLogic\ConditionalLogicRule(); - - // Forms - $this->instances['save_and_continue'] = new Form\SaveAndContinue(); - $this->instances['form_notification_routing'] = new Form\FormNotificationRouting(); - $this->instances['form_notification'] = new Form\FormNotification(); - $this->instances['form_confirmation'] = new Form\FormConfirmation(); - $this->instances['form_pagination'] = new Form\FormPagination(); - $this->instances['form'] = new Form\Form( $this->instances['form_data_manipulator'] ); - - // Fields - $this->instances['address_field'] = new Field\AddressField(); - $this->instances['calculation_field'] = new Field\CalculationField(); - $this->instances['captcha_field'] = new Field\CaptchaField(); - $this->instances['chained_select_field'] = new Field\ChainedSelectField(); - $this->instances['checkbox_field'] = new Field\CheckboxField(); - $this->instances['date_field'] = new Field\DateField(); - $this->instances['email_field'] = new Field\EmailField(); - $this->instances['file_upload_field'] = new Field\FileUploadField(); - $this->instances['hidden_field'] = new Field\HiddenField(); - $this->instances['html_field'] = new Field\HtmlField(); - $this->instances['list_field'] = new Field\ListField(); - $this->instances['multi_select_field'] = new Field\MultiSelectField(); - $this->instances['name_field'] = new Field\NameField(); - $this->instances['number_field'] = new Field\NumberField(); - $this->instances['page_field'] = new Field\PageField(); - $this->instances['password_field'] = new Field\PasswordField(); - $this->instances['phone_field'] = new Field\PhoneField(); - $this->instances['post_category_field'] = new Field\PostCategoryField(); - $this->instances['post_content_field'] = new Field\PostContentField(); - $this->instances['post_custom_field'] = new Field\PostCustomField(); - $this->instances['post_excerpt_field'] = new Field\PostExcerptField(); - $this->instances['post_image_field'] = new Field\PostImageField(); - $this->instances['post_tags_field'] = new Field\PostTagsField(); - $this->instances['post_title_field'] = new Field\PostTitleField(); - $this->instances['radio_field'] = new Field\RadioField(); - $this->instances['section_field'] = new Field\SectionField(); - $this->instances['signature_field'] = new Field\SignatureField(); - $this->instances['select_field'] = new Field\SelectField(); - $this->instances['text_area_field'] = new Field\TextAreaField(); - $this->instances['text_field'] = new Field\TextField(); - $this->instances['time_field'] = new Field\TimeField(); - $this->instances['website_field'] = new Field\WebsiteField(); - - // Field Properties - $this->instances['chained_select_choice_property'] = new FieldProperty\ChainedSelectChoiceProperty(); - $this->instances['checkbox_input_property'] = new FieldProperty\CheckboxInputProperty(); - $this->instances['choice_property'] = new FieldProperty\ChoiceProperty(); - $this->instances['input_property'] = new FieldProperty\InputProperty(); - $this->instances['list_choice_property'] = new FieldProperty\ListChoiceProperty(); - $this->instances['multi_select_choice_property'] = new FieldProperty\MultiSelectChoiceProperty(); - $this->instances['password_input_property'] = new FieldProperty\PasswordInputProperty(); - - // Field Values - $this->instances['address_field_value'] = new FieldValue\AddressFieldValue(); - $this->instances['chained_select_field_value'] = new FieldValue\ChainedSelectFieldValue(); - $this->instances['checkbox_field_values'] = new FieldValue\CheckboxFieldValue(); - $this->instances['date_field_values'] = new FieldValue\DateFieldValue(); - $this->instances['email_field_value'] = new FieldValue\EmailFieldValue(); - $this->instances['file_upload_field_value'] = new FieldValue\FileUploadFieldValue(); - $this->instances['multi_select_field_value'] = new FieldValue\MultiSelectFieldValue(); - $this->instances['name_field_value'] = new FieldValue\NameFieldValue(); - $this->instances['number_field_value'] = new FieldValue\NumberFieldValue(); - $this->instances['phone_field_values'] = new FieldValue\PhoneFieldValue(); - $this->instances['radio_field_values'] = new FieldValue\RadioFieldValue(); - $this->instances['select_field_value'] = new FieldValue\SelectFieldValue(); - $this->instances['signature_field_value'] = new FieldValue\SignatureFieldValue(); - $this->instances['text_area_field_value'] = new FieldValue\TextAreaFieldValue(); - $this->instances['text_field_value'] = new FieldValue\TextFieldValue(); - $this->instances['time_field_value'] = new FieldValue\TimeFieldValue(); - $this->instances['website_field_value'] = new FieldValue\WebsiteFieldValue(); - - // Entries - $this->instances['entry'] = new Entry\Entry( $this->instances['entry_data_manipulator'], $this->instances['draft_entry_data_manipulator'] ); - $this->instances['entry_form'] = new Entry\EntryForm( $this->instances['form_data_manipulator'] ); - $this->instances['entry_user'] = new Entry\EntryUser(); - - // Input - $this->instances['checkbox_input'] = new Input\CheckboxInput(); - $this->instances['entries_date_fiters_input'] = new Input\EntriesDateFiltersInput(); - $this->instances['entries_field_fiters_input'] = new Input\EntriesFieldFiltersInput(); - $this->instances['entries_sorting_input'] = new Input\EntriesSortingInput(); - - // Unions - $this->instances['object_field_union'] = new Union\ObjectFieldUnion( $this->instances ); - $this->instances['object_field_value_union'] = new Union\ObjectFieldValueUnion( $this->instances ); - - // Connections - $this->instances['entry_field_connection'] = new Connections\EntryFieldConnection( $this->instances ); - $this->instances['form_field_connection'] = new Connections\FormFieldConnection(); - $this->instances['root_query_entries_connection'] = new Connections\RootQueryEntriesConnection(); - $this->instances['root_query_forms_connection'] = new Connections\RootQueryFormsConnection(); - - // Enums - $this->instances['form_status_enum'] = new Enum\FormStatusEnum(); - $this->instances['field_filters_operator_input_enum'] = new Enum\FieldFiltersOperatorInputEnum(); - - // Field errors - $this->instances['field_error'] = new FieldError(); - - // Draft entry mutations - $this->instances['create_draft_entry'] = new Mutations\CreateDraftEntry(); - $this->instances['delete_draft_entry'] = new Mutations\DeleteDraftEntry(); - $this->instances['submit_draft_entry'] = new Mutations\SubmitDraftEntry( $this->instances['entry_data_manipulator'] ); - $this->instances['update_draft_entry_checkbox_field_value'] = new Mutations\UpdateDraftEntryCheckboxFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_date_field_value'] = new Mutations\UpdateDraftEntryDateFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_email_field_value'] = new Mutations\UpdateDraftEntryEmailFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_multi_select_field_value'] = new Mutations\UpdateDraftEntryMultiSelectFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_number_field_value'] = new Mutations\UpdateDraftEntryNumberFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_phone_field_value'] = new Mutations\UpdateDraftEntryPhoneFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_radio_field_value'] = new Mutations\UpdateDraftEntryRadioFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_select_field_value'] = new Mutations\UpdateDraftEntrySelectFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_signature_field_value'] = new Mutations\UpdateDraftEntrySignatureFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_text_area_field_value'] = new Mutations\UpdateDraftEntryTextAreaFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_text_field_value'] = new Mutations\UpdateDraftEntryTextFieldValue( $this->instances['draft_entry_data_manipulator'] ); - $this->instances['update_draft_entry_website_field_value'] = new Mutations\UpdateDraftEntryWebsiteFieldValue( $this->instances['draft_entry_data_manipulator'] ); - } - - private function register_hooks() { - foreach ( $this->get_hookable_instances() as $instance ) { - $instance->register_hooks(); - } - } - - private function get_hookable_instances() { - return array_filter( $this->instances, function( $instance ) { - return $instance instanceof Hookable; - } ); - } -} - -// @TODO: Handle this more gracefully to bump up the number of form fields returned. -add_filter( 'graphql_connection_max_query_amount', function() { - return 500; -}, 11 ); From 1f230a713cc9d6059d7f0c6216e2e505dde84336 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 11:45:42 +0200 Subject: [PATCH 10/17] Add WPGraphQLGravityForms support --- src/class-config.php | 453 +++++++++++++++++++++++-------------------- 1 file changed, 239 insertions(+), 214 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index ca7d79d..a2afadd 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -16,9 +16,14 @@ use WPGraphQL\Model\Post; use WPGraphQL\Model\Term; use WPGraphQL\Model\User; +use WPGraphQLGravityForms\Types\Form\FormPagination; +use WPGraphQLGravityForms\Types\Form\FormNotification; +use WPGraphQLGravityForms\Types\Form\FormConfirmation; +use WPGraphQLGravityForms\Types\Form\SaveAndContinue; use WPGraphQLGravityForms\Types\Union\ObjectFieldUnion; use WPGraphQLGravityForms\Types\Button\Button; + /** * Config class. */ @@ -1032,232 +1037,252 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { * * @see: https://github.com/wp-graphql/wp-graphql-acf/issues/25 */ + $field_type_name = 'ACF_GravityForm'; + if ( $this->type_registry->get_type( $field_type_name ) == $field_type_name ) { + $field_config['type'] = $field_type_name; + break; + } + + register_graphql_object_type( + $field_type_name, + [ + 'description' => __( 'Gravity Form Object', 'wp-graphql-acf' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + 'description' => __( 'Unique global ID for the object.', 'wp-graphql-acf' ), + ], + 'formId' => [ + 'type' => 'Int', + 'description' => __( 'Form ID.', 'wp-graphql-acf' ), + ], + 'title' => [ + 'type' => 'String', + 'description' => __( 'Form title.', 'wp-graphql-acf' ), + ], + 'description' => [ + 'type' => 'String', + 'description' => __( 'Form description.', 'wp-graphql-acf' ), + ], + 'labelPlacement' => [ + 'type' => 'String', + 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-acf' ), + ], + 'descriptionPlacement' => [ + 'type' => 'String', + 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), + ], + 'button' => [ + 'type' => Button::TYPE, + 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), + ], + 'useCurrentUserAsAuthor' => [ + 'type' => 'Boolean', + 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-acf' ), + ], + 'postAuthor' => [ + 'type' => 'Int', + 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-acf' ), + ], + 'postCategory' => [ + 'type' => 'Int', + 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-acf' ), + ], + 'postContentTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-acf' ), + ], + 'postContentTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-acf' ), + ], + 'postFormat' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-acf' ), + ], + 'postStatus' => [ + 'type' => 'String', + 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-acf' ), + ], + 'postTitleTemplate' => [ + 'type' => 'String', + 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-acf' ), + ], + 'postTitleTemplateEnabled' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), + ], + 'lastPageButton' => [ + 'type' => Button::TYPE, + 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), + ], + 'pagination' => [ + 'type' => FormPagination::TYPE, + 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), + ], + 'firstPageCssClass' => [ + 'type' => 'String', + 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), + ], + 'notifications' => [ + 'type' => [ 'list_of' => FormNotification::TYPE ], + 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), + ], + 'confirmations' => [ + 'type' => [ 'list_of' => FormConfirmation::TYPE ], + 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), + ], + 'cssClass' => [ + 'type' => 'String', + 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), + ], + 'enableHoneypot' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-acf' ), + ], + 'enableAnimation' => [ + 'type' => 'Boolean', + 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), + ], + 'save' => [ + 'type' => SaveAndContinue::TYPE, + 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), + ], + 'limitEntries' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), + ], + 'limitEntriesCount' => [ + 'type' => 'Int', + 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-acf' ), + ], + 'limitEntriesPeriod' => [ + 'type' => 'String', + 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-acf' ), + ], + 'limitEntriesMessage' => [ + 'type' => 'String', + 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-acf' ), + ], + 'scheduleForm' => [ + 'type' => 'Boolean', + 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-acf' ), + ], + 'scheduleStart' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-acf' ), + ], + 'scheduleStartAmpm' => [ + 'type' => 'String', + 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-acf' ), + ], + 'scheduleEnd' => [ + 'type' => 'String', + 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndHour' => [ + 'type' => 'Int', + 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndMinute' => [ + 'type' => 'Int', + 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-acf' ), + ], + 'scheduleEndAmpm' => [ + 'type' => 'String', + 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-acf' ), + ], + 'scheduleMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-acf' ), + ], + 'schedulePendingMessage' => [ + 'type' => 'String', + 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-acf' ), + ], + 'subLabelPlacement' => [ + 'type' => 'String', + 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-acf' ), + ], + 'cssClassList' => [ + 'type' => [ 'list_of' => 'String' ], + 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), + ], + 'requireLogin' => [ + 'type' => 'Boolean', + 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-acf' ), + ], + 'requireLoginMessage' => [ + 'type' => 'String', + 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-acf' ), + ], + 'nextFieldId' => [ + 'type' => 'Int', + 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-acf' ), + ], + 'isActive' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is active.', 'wp-graphql-acf' ), + ], + 'dateCreated' => [ + 'type' => 'String', + 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-acf' ), + ], + 'isTrash' => [ + 'type' => 'Boolean', + 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-acf' ), + ], + ], + ] + ); + + // Single form if ( empty( $acf_field['multiple'] ) ) { if ($acf_field['return_format'] === 'post_object') { - - $field_type_name = 'GravityForm'; - if ( $this->type_registry->get_type( $field_type_name ) == $field_type_name ) { - $field_config['type'] = $field_type_name; - break; - } - - register_graphql_object_type( - $field_type_name, - [ - 'description' => __( 'Gravity Form Object', 'wp-graphql-acf' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( 'Unique global ID for the object.', 'wp-graphql-acf' ), - ], - 'formId' => [ - 'type' => 'Int', - 'description' => __( 'Form ID.', 'wp-graphql-acf' ), - ], - 'title' => [ - 'type' => 'String', - 'description' => __( 'Form title.', 'wp-graphql-acf' ), - ], - 'description' => [ - 'type' => 'String', - 'description' => __( 'Form description.', 'wp-graphql-acf' ), - ], - 'labelPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-acf' ), - ], - 'descriptionPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), - ], - 'button' => [ - 'type' => Button::TYPE, - 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), - ], - 'useCurrentUserAsAuthor' => [ - 'type' => 'Boolean', - 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-acf' ), - ], - 'postAuthor' => [ - 'type' => 'Int', - 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-acf' ), - ], - 'postCategory' => [ - 'type' => 'Int', - 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-acf' ), - ], - 'postContentTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-acf' ), - ], - 'postContentTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-acf' ), - ], - 'postFormat' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-acf' ), - ], - 'postStatus' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-acf' ), - ], - 'postTitleTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-acf' ), - ], - 'postTitleTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), - ], - 'lastPageButton' => [ - 'type' => Button::TYPE, - 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), - ], - 'pagination' => [ - 'type' => FormPagination::TYPE, - 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), - ], - 'firstPageCssClass' => [ - 'type' => 'String', - 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), - ], - 'notifications' => [ - 'type' => [ 'list_of' => FormNotification::TYPE ], - 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), - ], - 'confirmations' => [ - 'type' => [ 'list_of' => FormConfirmation::TYPE ], - 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), - ], - 'cssClass' => [ - 'type' => 'String', - 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), - ], - 'enableHoneypot' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-acf' ), - ], - 'enableAnimation' => [ - 'type' => 'Boolean', - 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), - ], - 'save' => [ - 'type' => SaveAndContinue::TYPE, - 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), - ], - 'limitEntries' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), - ], - 'limitEntriesCount' => [ - 'type' => 'Int', - 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-acf' ), - ], - 'limitEntriesPeriod' => [ - 'type' => 'String', - 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-acf' ), - ], - 'limitEntriesMessage' => [ - 'type' => 'String', - 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-acf' ), - ], - 'scheduleForm' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-acf' ), - ], - 'scheduleStart' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartAmpm' => [ - 'type' => 'String', - 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-acf' ), - ], - 'scheduleEnd' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndAmpm' => [ - 'type' => 'String', - 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-acf' ), - ], - 'scheduleMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-acf' ), - ], - 'schedulePendingMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-acf' ), - ], - 'subLabelPlacement' => [ - 'type' => 'String', - 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-acf' ), - ], - 'cssClassList' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), - ], - 'requireLogin' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-acf' ), - ], - 'requireLoginMessage' => [ - 'type' => 'String', - 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-acf' ), - ], - 'nextFieldId' => [ - 'type' => 'Int', - 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-acf' ), - ], - 'isActive' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is active.', 'wp-graphql-acf' ), - ], - 'dateCreated' => [ - 'type' => 'String', - 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-acf' ), - ], - 'isTrash' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-acf' ), - ], - ], - ] - ); $field_config['type'] = $field_type_name; $field_config['resolve'] = function( $root ) use ( $acf_field ) { $value = $this->get_acf_field_value( $root, $acf_field ); - $gform = class_exists( 'GFAPI' ) ? \GFAPI::get_form($value) : null; + $gform_object = class_exists( 'GFAPI' ) ? \GFAPI::get_form($value) : null; - return ! empty( $gform ) ? $gform : null; + return ! empty( $gform_object ) ? $gform_object : null; }; } else { $field_config['type'] = 'Integer'; } + // Multiple forms } else { - $field_config['type'] = [ 'list_of' => 'String' ]; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $value = $this->get_acf_field_value( $root, $acf_field ); + if ($acf_field['return_format'] === 'post_object') { + $field_config['type'] = [ 'list_of' => $field_type_name ]; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $forms = []; + $value = $this->get_acf_field_value( $root, $acf_field ); - return ! empty( $value ) && is_array( $value ) ? $value : []; - }; + if ( ! empty( $value ) && is_array( $value ) ) { + foreach ( $value as $form_id ) { + $gform_object = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; + $forms[] = $gform_object; + } + } + + + return ! empty( $forms ) ? $forms : []; + }; + } else { + $field_config['type'] = [ 'list_of' => 'Integer' ]; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $value = $this->get_acf_field_value( $root, $acf_field ); + + return ! empty( $value ) && is_array( $value ) ? $value : []; + }; + } } break; default: From 1e763e0538157a42191479ded211cdc991183526 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 14:24:34 +0200 Subject: [PATCH 11/17] Use Form type & data manipulator from WPGraphQLGravityForms --- src/class-config.php | 241 +++++-------------------------------------- 1 file changed, 28 insertions(+), 213 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index a2afadd..345b110 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -16,6 +16,8 @@ use WPGraphQL\Model\Post; use WPGraphQL\Model\Term; use WPGraphQL\Model\User; +use WPGraphQLGravityForms\Types\Form\Form; +use WPGraphQLGravityForms\DataManipulators; use WPGraphQLGravityForms\Types\Form\FormPagination; use WPGraphQLGravityForms\Types\Form\FormNotification; use WPGraphQLGravityForms\Types\Form\FormConfirmation; @@ -31,6 +33,12 @@ class Config { protected $type_registry; + /** + * FormDataManipulator instance. + */ + private $fields_data_manipulator; + private $form_data_manipulator; + /** * Initialize WPGraphQL to ACF * @@ -43,6 +51,9 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { */ $this->type_registry = $type_registry; + $this->fields_data_manipulator = new DataManipulators\FieldsDataManipulator(); + $this->form_data_manipulator = new DataManipulators\FormDataManipulator( $this->fields_data_manipulator ); + /** * Add ACF Fields to GraphQL Types */ @@ -1037,222 +1048,26 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { * * @see: https://github.com/wp-graphql/wp-graphql-acf/issues/25 */ - $field_type_name = 'ACF_GravityForm'; + $field_type_name = Form::TYPE; if ( $this->type_registry->get_type( $field_type_name ) == $field_type_name ) { $field_config['type'] = $field_type_name; break; } - - register_graphql_object_type( - $field_type_name, - [ - 'description' => __( 'Gravity Form Object', 'wp-graphql-acf' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - 'description' => __( 'Unique global ID for the object.', 'wp-graphql-acf' ), - ], - 'formId' => [ - 'type' => 'Int', - 'description' => __( 'Form ID.', 'wp-graphql-acf' ), - ], - 'title' => [ - 'type' => 'String', - 'description' => __( 'Form title.', 'wp-graphql-acf' ), - ], - 'description' => [ - 'type' => 'String', - 'description' => __( 'Form description.', 'wp-graphql-acf' ), - ], - 'labelPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field labels are displayed on top of the fields (top_label), beside the fields and aligned to the left (left_label) or beside the fields and aligned to the right (right_label).', 'wp-graphql-acf' ), - ], - 'descriptionPlacement' => [ - 'type' => 'String', - 'description' => __( 'Determines if the field description is displayed above the field input (i.e. immediately after the field label) or below the field input.', 'wp-graphql-acf' ), - ], - 'button' => [ - 'type' => Button::TYPE, - 'description' => __( 'Contains the form button settings such as the button text or image button source.', 'wp-graphql-acf' ), - ], - 'useCurrentUserAsAuthor' => [ - 'type' => 'Boolean', - 'description' => __( 'For forms with Post fields, this determines if the post should be created using the current logged in user as the author. 1 to use the current user, 0 otherwise.', 'wp-graphql-acf' ), - ], - 'postAuthor' => [ - 'type' => 'Int', - 'description' => __( 'When useCurrentUserAsAuthor is set to 0, this property contains the user Id that will be used as the Post author.', 'wp-graphql-acf' ), - ], - 'postCategory' => [ - 'type' => 'Int', - 'description' => __( 'Form forms with Post fields, but without a Post Category field, this property determines the default category that the post will be associated with when created.', 'wp-graphql-acf' ), - ], - 'postContentTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post content. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post content. Only applicable when postContentTemplateEnabled is true.', 'wp-graphql-acf' ), - ], - 'postContentTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post template functionality is enabled. When enabled, the post content will be created based on the template specified by postContentTemplate.', 'wp-graphql-acf' ), - ], - 'postFormat' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the format that the Post should be created with.', 'wp-graphql-acf' ), - ], - 'postStatus' => [ - 'type' => 'String', - 'description' => __( 'For forms with Post fields, determines the status that the Post should be created with.', 'wp-graphql-acf' ), - ], - 'postTitleTemplate' => [ - 'type' => 'String', - 'description' => __( 'Template to be used when creating the post title. Field variables (i.e. {Name:3} ) can be added to the template to insert user submitted values into the post title. Only applicable when postTitleTemplateEnabled is true', 'wp-graphql-acf' ), - ], - 'postTitleTemplateEnabled' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines if the post title template functionality is enabled. When enabled, the post title will be created based on the template specified by postTitleTemplate.', 'wp-graphql-acf' ), - ], - 'lastPageButton' => [ - 'type' => Button::TYPE, - 'description' => __( 'Last page button data.', 'wp-graphql-acf' ), - ], - 'pagination' => [ - 'type' => FormPagination::TYPE, - 'description' => __( 'Pagination data.', 'wp-graphql-acf' ), - ], - 'firstPageCssClass' => [ - 'type' => 'String', - 'description' => __( 'CSS class for the first page.', 'wp-graphql-acf' ), - ], - 'notifications' => [ - 'type' => [ 'list_of' => FormNotification::TYPE ], - 'description' => __( 'The properties for all the email notifications which exist for a form.', 'wp-graphql-acf' ), - ], - 'confirmations' => [ - 'type' => [ 'list_of' => FormConfirmation::TYPE ], - 'description' => __( 'Contains the form confirmation settings such as confirmation text or redirect URL', 'wp-graphql-acf' ), - ], - 'cssClass' => [ - 'type' => 'String', - 'description' => __( 'String containing the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), - ], - 'enableHoneypot' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if the form has the Honeypot spam-protection feature.', 'wp-graphql-acf' ), - ], - 'enableAnimation' => [ - 'type' => 'Boolean', - 'description' => __( 'When enabled, conditional logic hide/show operation will be performed with a jQuery slide animation. Only applicable to forms with conditional logic.', 'wp-graphql-acf' ), - ], - 'save' => [ - 'type' => SaveAndContinue::TYPE, - 'description' => __( '"Save and Continue" data.', 'wp-graphql-acf' ), - ], - 'limitEntries' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form has a limit on the number of submissions. 1 if the form limits submissions, 0 otherwise.', 'wp-graphql-acf' ), - ], - 'limitEntriesCount' => [ - 'type' => 'Int', - 'description' => __( 'When limitEntries is set to 1, this property specifies the number of submissions allowed.', 'wp-graphql-acf' ), - ], - 'limitEntriesPeriod' => [ - 'type' => 'String', - 'description' => __( 'When limitEntries is set to 1, this property specifies the time period during which submissions are allowed. Options are "day", "week", "month" and "year".', 'wp-graphql-acf' ), - ], - 'limitEntriesMessage' => [ - 'type' => 'String', - 'description' => __( 'Message that will be displayed when the maximum number of submissions have been reached.', 'wp-graphql-acf' ), - ], - 'scheduleForm' => [ - 'type' => 'Boolean', - 'description' => __( 'Specifies if this form is scheduled to be displayed only during a certain configured date/time.', 'wp-graphql-acf' ), - ], - 'scheduleStart' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become active/visible.', 'wp-graphql-acf' ), - ], - 'scheduleStartAmpm' => [ - 'type' => 'String', - 'description' => __( '"am" or "pm". Applies to scheduleStartHour', 'wp-graphql-acf' ), - ], - 'scheduleEnd' => [ - 'type' => 'String', - 'description' => __( 'Date in the format (mm/dd/yyyy) that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndHour' => [ - 'type' => 'Int', - 'description' => __( 'Hour (1 to 12) that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndMinute' => [ - 'type' => 'Int', - 'description' => __( 'Minute that the form will become inactive/hidden.', 'wp-graphql-acf' ), - ], - 'scheduleEndAmpm' => [ - 'type' => 'String', - 'description' => __( '"am? or "pm?. Applies to scheduleEndHour', 'wp-graphql-acf' ), - ], - 'scheduleMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is no longer available', 'wp-graphql-acf' ), - ], - 'schedulePendingMessage' => [ - 'type' => 'String', - 'description' => __( 'Message to be displayed when form is not yet available.', 'wp-graphql-acf' ), - ], - 'subLabelPlacement' => [ - 'type' => 'String', - 'description' => __( 'How sub-labels are aligned.', 'wp-graphql-acf' ), - ], - 'cssClassList' => [ - 'type' => [ 'list_of' => 'String' ], - 'description' => __( 'Array of the custom CSS classes to be added to the tag.', 'wp-graphql-acf' ), - ], - 'requireLogin' => [ - 'type' => 'Boolean', - 'description' => __( 'Whether the form is configured to be displayed only to logged in users.', 'wp-graphql-acf' ), - ], - 'requireLoginMessage' => [ - 'type' => 'String', - 'description' => __( 'When requireLogin is set to true, this controls the message displayed when non-logged in user tries to access the form.', 'wp-graphql-acf' ), - ], - 'nextFieldId' => [ - 'type' => 'Int', - 'description' => __( 'The ID to assign to the next field that is added to the form.', 'wp-graphql-acf' ), - ], - 'isActive' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is active.', 'wp-graphql-acf' ), - ], - 'dateCreated' => [ - 'type' => 'String', - 'description' => __( 'The date the form was created in this format: YYYY-MM-DD HH:mm:ss.', 'wp-graphql-acf' ), - ], - 'isTrash' => [ - 'type' => 'Boolean', - 'description' => __( 'Determines whether the form is in the trash.', 'wp-graphql-acf' ), - ], - ], - ] - ); // Single form if ( empty( $acf_field['multiple'] ) ) { if ($acf_field['return_format'] === 'post_object') { - $field_config['type'] = $field_type_name; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $value = $this->get_acf_field_value( $root, $acf_field ); - $gform_object = class_exists( 'GFAPI' ) ? \GFAPI::get_form($value) : null; + $field_config['type'] = $field_type_name; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $form_id = $this->get_acf_field_value( $root, $acf_field ); + $form_raw = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; - return ! empty( $gform_object ) ? $gform_object : null; + if ( ! $form_raw ) { + throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); + } + + $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); + return apply_filters( 'wp_graphql_gf_form_object', $form ); }; } else { $field_config['type'] = 'Integer'; @@ -1262,13 +1077,13 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { if ($acf_field['return_format'] === 'post_object') { $field_config['type'] = [ 'list_of' => $field_type_name ]; $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $forms = []; - $value = $this->get_acf_field_value( $root, $acf_field ); + $forms = []; + $form_ids = $this->get_acf_field_value( $root, $acf_field ); - if ( ! empty( $value ) && is_array( $value ) ) { - foreach ( $value as $form_id ) { - $gform_object = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; - $forms[] = $gform_object; + if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { + foreach ( $form_ids as $form_id ) { + $form_raw = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; + $forms[] = $form_raw; } } From eb9b5c632bcbea736eaf2a8b65d2a99050923555 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 15:41:36 +0200 Subject: [PATCH 12/17] Check if WPGraphQLGravityForms exists --- src/class-config.php | 93 +++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 345b110..0203437 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -16,6 +16,8 @@ use WPGraphQL\Model\Post; use WPGraphQL\Model\Term; use WPGraphQL\Model\User; + +// WPGraphQLGravityForms classes use WPGraphQLGravityForms\Types\Form\Form; use WPGraphQLGravityForms\DataManipulators; use WPGraphQLGravityForms\Types\Form\FormPagination; @@ -25,7 +27,6 @@ use WPGraphQLGravityForms\Types\Union\ObjectFieldUnion; use WPGraphQLGravityForms\Types\Button\Button; - /** * Config class. */ @@ -45,12 +46,14 @@ class Config { * @param \WPGraphQL\Registry\TypeRegistry $type_registry Instance of the WPGraphQL TypeRegistry */ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { - /** * Set the TypeRegistry */ $this->type_registry = $type_registry; + /** + * Set the DataManipulators + */ $this->fields_data_manipulator = new DataManipulators\FieldsDataManipulator(); $this->form_data_manipulator = new DataManipulators\FormDataManipulator( $this->fields_data_manipulator ); @@ -1039,57 +1042,69 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { }; } break; - case 'forms' && class_exists( 'ACFGravityformsField\\Init' ) : - /** - * If the select field is configured to not allow multiple values - * the field will return a string, but if it is configured to allow - * multiple values it will return a list of strings, and an empty array - * if no values are set. - * - * @see: https://github.com/wp-graphql/wp-graphql-acf/issues/25 - */ - $field_type_name = Form::TYPE; - if ( $this->type_registry->get_type( $field_type_name ) == $field_type_name ) { - $field_config['type'] = $field_type_name; - break; - } - + /* + * Add acf-gravityforms-add-on support + */ + case 'forms' && class_exists( 'GFAPI' ) && class_exists( 'ACFGravityformsField\\Init' ) : // Single form if ( empty( $acf_field['multiple'] ) ) { if ($acf_field['return_format'] === 'post_object') { - $field_config['type'] = $field_type_name; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $form_id = $this->get_acf_field_value( $root, $acf_field ); - $form_raw = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; + if (class_exists('WPGraphQLGravityForms\WPGraphQLGravityForms\Types\Form')) { + $field_config['type'] = Form::TYPE; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $form_id = $this->get_acf_field_value( $root, $acf_field ); + $form_raw = \GFAPI::get_form($form_id); + + if ( ! $form_raw ) { + throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); + } - if ( ! $form_raw ) { - throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); - } + $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); + return apply_filters( 'wp_graphql_gf_form_object', $form ); + }; + } else { + $field_config['type'] = 'String'; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $message = __( 'WPGraphQL for Gravity Forms plugin must be installed and activated in order to retrieve the Gravity Form object.', 'wp-graphql-acf' ); - $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); - return apply_filters( 'wp_graphql_gf_form_object', $form ); - }; + return $message; + }; + } } else { $field_config['type'] = 'Integer'; } // Multiple forms } else { - if ($acf_field['return_format'] === 'post_object') { - $field_config['type'] = [ 'list_of' => $field_type_name ]; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $forms = []; - $form_ids = $this->get_acf_field_value( $root, $acf_field ); + if ($acf_field['return_format'] === 'post_object' && class_exists('WPGraphQLGravityForms')) { + if (class_exists('WPGraphQLGravityForms\WPGraphQLGravityForms\Types\Form')) { + $field_config['type'] = [ 'list_of' => $field_type_name ]; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $forms = []; + $form_ids = $this->get_acf_field_value( $root, $acf_field ); + + if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { + foreach ( $form_ids as $form_id ) { + $form_raw = \GFAPI::get_form($form_id); + + if ( ! $form_raw ) { + throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); + } - if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { - foreach ( $form_ids as $form_id ) { - $form_raw = class_exists( 'GFAPI' ) ? \GFAPI::get_form($form_id) : null; - $forms[] = $form_raw; + $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); + $forms[] = $form; + } } - } + return ! empty( $forms ) ? $forms : []; + }; + } else { + $field_config['type'] = 'String'; + $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $message = __( 'WPGraphQL for Gravity Forms plugin must be installed and activated in order to retrieve the Gravity Form object.', 'wp-graphql-acf' ); - return ! empty( $forms ) ? $forms : []; - }; + return $message; + }; + } } else { $field_config['type'] = [ 'list_of' => 'Integer' ]; $field_config['resolve'] = function( $root ) use ( $acf_field ) { From 1af1503ad63d07c171cdced1c52d05bcfa65fdde Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 18 May 2020 17:06:24 +0200 Subject: [PATCH 13/17] Add correct check for wp-graphql-gravity-forms plugin --- src/class-config.php | 88 ++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 57 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 0203437..76ca777 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -27,6 +27,7 @@ use WPGraphQLGravityForms\Types\Union\ObjectFieldUnion; use WPGraphQLGravityForms\Types\Button\Button; + /** * Config class. */ @@ -1046,68 +1047,41 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { * Add acf-gravityforms-add-on support */ case 'forms' && class_exists( 'GFAPI' ) && class_exists( 'ACFGravityformsField\\Init' ) : - // Single form - if ( empty( $acf_field['multiple'] ) ) { - if ($acf_field['return_format'] === 'post_object') { - if (class_exists('WPGraphQLGravityForms\WPGraphQLGravityForms\Types\Form')) { - $field_config['type'] = Form::TYPE; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $form_id = $this->get_acf_field_value( $root, $acf_field ); - $form_raw = \GFAPI::get_form($form_id); - - if ( ! $form_raw ) { - throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); + // GravityForm object + if ($acf_field['return_format'] === 'post_object' && is_plugin_active('wp-graphql-gravity-forms/wp-graphql-gravity-forms.php')) { + if ( empty( $acf_field['multiple'] ) ) { + $field_config['type'] = Form::TYPE; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $form_id = $this->get_acf_field_value( $root, $acf_field ); + $form_raw = \GFAPI::get_form($form_id); + $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); + + return apply_filters( 'wp_graphql_gf_form_object', $form ); + }; + } else { + $field_config['type'] = [ 'list_of' => Form::TYPE ]; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $forms = []; + $form_ids = $this->get_acf_field_value( $root, $acf_field ); + + if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { + foreach ( $form_ids as $form_id ) { + $form_raw = \GFAPI::get_form($form_id); + $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); + $forms[] = $form; } + } - $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); - return apply_filters( 'wp_graphql_gf_form_object', $form ); - }; - } else { - $field_config['type'] = 'String'; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $message = __( 'WPGraphQL for Gravity Forms plugin must be installed and activated in order to retrieve the Gravity Form object.', 'wp-graphql-acf' ); - - return $message; - }; - } - } else { - $field_config['type'] = 'Integer'; + return ! empty( $forms ) ? $forms : []; + }; } - // Multiple forms + // Form id } else { - if ($acf_field['return_format'] === 'post_object' && class_exists('WPGraphQLGravityForms')) { - if (class_exists('WPGraphQLGravityForms\WPGraphQLGravityForms\Types\Form')) { - $field_config['type'] = [ 'list_of' => $field_type_name ]; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $forms = []; - $form_ids = $this->get_acf_field_value( $root, $acf_field ); - - if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { - foreach ( $form_ids as $form_id ) { - $form_raw = \GFAPI::get_form($form_id); - - if ( ! $form_raw ) { - throw new UserError( __( 'A valid form ID must be provided.', 'wp-graphql-acf' ) ); - } - - $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); - $forms[] = $form; - } - } - - return ! empty( $forms ) ? $forms : []; - }; - } else { - $field_config['type'] = 'String'; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { - $message = __( 'WPGraphQL for Gravity Forms plugin must be installed and activated in order to retrieve the Gravity Form object.', 'wp-graphql-acf' ); - - return $message; - }; - } + if ( empty( $acf_field['multiple'] ) ) { + $field_config['type'] = 'Integer'; } else { - $field_config['type'] = [ 'list_of' => 'Integer' ]; - $field_config['resolve'] = function( $root ) use ( $acf_field ) { + $field_config['type'] = [ 'list_of' => 'Integer' ]; + $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { $value = $this->get_acf_field_value( $root, $acf_field ); return ! empty( $value ) && is_array( $value ) ? $value : []; From 6a066e7aa165ff9ce95e792a1ba913524a64f249 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Tue, 19 May 2020 09:06:39 +0200 Subject: [PATCH 14/17] Remove add_acf_fields_to_pages --- src/class-config.php | 98 -------------------------------------------- 1 file changed, 98 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 76ca777..57712ab 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -70,7 +70,6 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { $this->add_acf_fields_to_individual_posts(); $this->add_acf_fields_to_users(); $this->add_acf_fields_to_options_pages(); - $this->add_acf_fields_to_pages(); } /** @@ -1797,101 +1796,4 @@ protected function add_acf_fields_to_options_pages() { } } } - - /** - * Add field groups for `page_type` and `page_template`. - * Note that these will show up for all pages in the schema, - * they will not be limited to the page types or templates assigned in the field group. - */ - protected function add_acf_fields_to_pages() { - - $page_field_groups = []; - - /** - * Get the field groups. - * - * TODO: Can we filter this to only page related ACF Field Groups? - */ - $field_groups = acf_get_field_groups(); - - /** - * We only want to add field groups for page type and template params. - * Page by location is already covered by `add_acf_fields_to_individual_posts`, - * so we do not want to duplicate that. - */ - $allowed_page_params = [ - 'page_type', - 'page_template', - ]; - - foreach ( $field_groups as $field_group ) { - if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { - foreach ( $field_group['location'] as $locations ) { - if ( ! empty( $locations ) && is_array( $locations ) ) { - foreach ( $locations as $location ) { - - /** - * If the operator is not equal to, we don't need to do anything, - * so we can just continue - */ - if ( '!=' === $location['operator'] ) { - continue; - } - - /** - * Add field group if the param is page related. - */ - if ( in_array( $location['param'], $allowed_page_params, true ) && '==' === $location['operator'] ) { - $page_field_groups[] = [ - 'type' => $location['param'], - 'field_group' => $field_group, - 'post_id' => $location['value'] - ]; - } - } - } - } - } - } - - - /** - * If no field groups are assigned to pages, we don't need to modify the Schema. - */ - if ( empty( $page_field_groups ) ) { - return; - } - - /** - * Loop over the field groups assigned to pages - * and register them to the Schema - */ - foreach ( $page_field_groups as $key => $group ) { - - if ( empty( $group['field_group'] ) || ! is_array( $group['field_group'] ) ) { - continue; - } - - // Initialize our field group object. - $field_group = $group['field_group']; - - $page_type_object = get_post_type_object('page'); - - $field_name = isset( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : Config::camel_case( $field_group['title'] ); - $field_group['type'] = 'group'; - $field_group['name'] = $field_name; - $description = $field_group['description'] ? $field_group['description'] . ' | ' : ''; - $config = [ - 'name' => $field_name, - 'description' => $description, - 'acf_field' => $field_group, - 'acf_field_group' => null, - 'resolve' => function( $root ) use ( $field_group ) { - return isset( $root ) ? $root : null; - } - ]; - - $this->register_graphql_field($page_type_object->graphql_single_name, $field_name, $config); - } - } } From 2522df3d538119e2aa7b310f2858bf994b53f627 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Tue, 19 May 2020 10:03:16 +0200 Subject: [PATCH 15/17] Add add_acf_fields_to_pages support --- src/class-config.php | 170 +++++++++++++++++++++++++------------------ 1 file changed, 100 insertions(+), 70 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 57712ab..9b8298e 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -17,16 +17,6 @@ use WPGraphQL\Model\Term; use WPGraphQL\Model\User; -// WPGraphQLGravityForms classes -use WPGraphQLGravityForms\Types\Form\Form; -use WPGraphQLGravityForms\DataManipulators; -use WPGraphQLGravityForms\Types\Form\FormPagination; -use WPGraphQLGravityForms\Types\Form\FormNotification; -use WPGraphQLGravityForms\Types\Form\FormConfirmation; -use WPGraphQLGravityForms\Types\Form\SaveAndContinue; -use WPGraphQLGravityForms\Types\Union\ObjectFieldUnion; -use WPGraphQLGravityForms\Types\Button\Button; - /** * Config class. @@ -35,12 +25,6 @@ class Config { protected $type_registry; - /** - * FormDataManipulator instance. - */ - private $fields_data_manipulator; - private $form_data_manipulator; - /** * Initialize WPGraphQL to ACF * @@ -52,12 +36,6 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { */ $this->type_registry = $type_registry; - /** - * Set the DataManipulators - */ - $this->fields_data_manipulator = new DataManipulators\FieldsDataManipulator(); - $this->form_data_manipulator = new DataManipulators\FormDataManipulator( $this->fields_data_manipulator ); - /** * Add ACF Fields to GraphQL Types */ @@ -70,6 +48,7 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { $this->add_acf_fields_to_individual_posts(); $this->add_acf_fields_to_users(); $this->add_acf_fields_to_options_pages(); + $this->add_acf_fields_to_pages(); } /** @@ -354,8 +333,7 @@ public static function get_supported_fields() { 'color_picker', 'group', 'repeater', - 'flexible_content', - 'forms' + 'flexible_content' ]; /** @@ -1042,52 +1020,6 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { }; } break; - /* - * Add acf-gravityforms-add-on support - */ - case 'forms' && class_exists( 'GFAPI' ) && class_exists( 'ACFGravityformsField\\Init' ) : - // GravityForm object - if ($acf_field['return_format'] === 'post_object' && is_plugin_active('wp-graphql-gravity-forms/wp-graphql-gravity-forms.php')) { - if ( empty( $acf_field['multiple'] ) ) { - $field_config['type'] = Form::TYPE; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $form_id = $this->get_acf_field_value( $root, $acf_field ); - $form_raw = \GFAPI::get_form($form_id); - $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); - - return apply_filters( 'wp_graphql_gf_form_object', $form ); - }; - } else { - $field_config['type'] = [ 'list_of' => Form::TYPE ]; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $forms = []; - $form_ids = $this->get_acf_field_value( $root, $acf_field ); - - if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { - foreach ( $form_ids as $form_id ) { - $form_raw = \GFAPI::get_form($form_id); - $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); - $forms[] = $form; - } - } - - return ! empty( $forms ) ? $forms : []; - }; - } - // Form id - } else { - if ( empty( $acf_field['multiple'] ) ) { - $field_config['type'] = 'Integer'; - } else { - $field_config['type'] = [ 'list_of' => 'Integer' ]; - $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { - $value = $this->get_acf_field_value( $root, $acf_field ); - - return ! empty( $value ) && is_array( $value ) ? $value : []; - }; - } - } - break; default: break; } @@ -1796,4 +1728,102 @@ protected function add_acf_fields_to_options_pages() { } } } + + /** + * Add field groups for `page_type` and `page_template`. + * Note that these will show up for all pages in the schema, + * they will not be limited to the page types or templates assigned in the field group. + */ + protected function add_acf_fields_to_pages() { + + $page_field_groups = []; + + /** + * Get the field groups. + * + * TODO: Can we filter this to only page related ACF Field Groups? + */ + $field_groups = acf_get_field_groups(); + + /** + * We only want to add field groups for page type and template params. + * Page by location is already covered by `add_acf_fields_to_individual_posts`, + * so we do not want to duplicate that. + */ + $allowed_page_params = [ + 'page_type', + 'page_template', + ]; + + foreach ( $field_groups as $field_group ) { + if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { + foreach ( $field_group['location'] as $locations ) { + if ( ! empty( $locations ) && is_array( $locations ) ) { + foreach ( $locations as $location ) { + + /** + * If the operator is not equal to, we don't need to do anything, + * so we can just continue + */ + if ( '!=' === $location['operator'] ) { + continue; + } + + /** + * Add field group if the param is page related. + */ + if ( in_array( $location['param'], $allowed_page_params, true ) && '==' === $location['operator'] ) { + $page_field_groups[] = [ + 'type' => $location['param'], + 'field_group' => $field_group, + 'post_id' => $location['value'] + ]; + } + } + } + } + } + } + + + /** + * If no field groups are assigned to pages, we don't need to modify the Schema. + */ + if ( empty( $page_field_groups ) ) { + return; + } + + /** + * Loop over the field groups assigned to pages + * and register them to the Schema + */ + foreach ( $page_field_groups as $key => $group ) { + + if ( empty( $group['field_group'] ) || ! is_array( $group['field_group'] ) ) { + continue; + } + + // Initialize our field group object. + $field_group = $group['field_group']; + + $page_type_object = get_post_type_object('page'); + + $field_name = isset( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : Config::camel_case( $field_group['title'] ); + $field_group['type'] = 'group'; + $field_group['name'] = $field_name; + $description = $field_group['description'] ? $field_group['description'] . ' | ' : ''; + $config = [ + 'name' => $field_name, + 'description' => $description, + 'acf_field' => $field_group, + 'acf_field_group' => null, + 'resolve' => function( $root ) use ( $field_group ) { + return isset( $root ) ? $root : null; + } + ]; + + $this->register_graphql_field($page_type_object->graphql_single_name, $field_name, $config); + + } + } } From 3d12947fb02f613bf3775954865febbe50970d5a Mon Sep 17 00:00:00 2001 From: Twansparant Date: Fri, 22 May 2020 17:12:48 +0200 Subject: [PATCH 16/17] Check for form id value --- src/class-config.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 57712ab..f22a933 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -1051,11 +1051,15 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { if ( empty( $acf_field['multiple'] ) ) { $field_config['type'] = Form::TYPE; $field_config['resolve'] = function( $root, $args ) use ( $acf_field ) { + $form = null; $form_id = $this->get_acf_field_value( $root, $acf_field ); - $form_raw = \GFAPI::get_form($form_id); - $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); - return apply_filters( 'wp_graphql_gf_form_object', $form ); + if ($form_id) { + $form_raw = \GFAPI::get_form($form_id); + $form = $this->form_data_manipulator->manipulate( $form_raw, $args ); + } + + return $form ? apply_filters( 'wp_graphql_gf_form_object', $form ) : null; }; } else { $field_config['type'] = [ 'list_of' => Form::TYPE ]; @@ -1065,9 +1069,11 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { if ( ! empty( $form_ids ) && is_array( $form_ids ) ) { foreach ( $form_ids as $form_id ) { - $form_raw = \GFAPI::get_form($form_id); - $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); - $forms[] = $form; + if ($form_id) { + $form_raw = \GFAPI::get_form($form_id); + $form = apply_filters( 'wp_graphql_gf_form_object', $this->form_data_manipulator->manipulate( $form_raw, $args ) ); + $forms[] = $form; + } } } From feee4e3ddfad2027b65f6a1bd9d6ebccd9ab4d10 Mon Sep 17 00:00:00 2001 From: Twansparant Date: Mon, 25 May 2020 10:05:18 +0200 Subject: [PATCH 17/17] Remove add_acf_fields_to_pages --- src/class-config.php | 99 -------------------------------------------- 1 file changed, 99 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index a572c5f..f22a933 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -70,7 +70,6 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { $this->add_acf_fields_to_individual_posts(); $this->add_acf_fields_to_users(); $this->add_acf_fields_to_options_pages(); - $this->add_acf_fields_to_pages(); } /** @@ -1803,102 +1802,4 @@ protected function add_acf_fields_to_options_pages() { } } } - - /** - * Add field groups for `page_type` and `page_template`. - * Note that these will show up for all pages in the schema, - * they will not be limited to the page types or templates assigned in the field group. - */ - protected function add_acf_fields_to_pages() { - - $page_field_groups = []; - - /** - * Get the field groups. - * - * TODO: Can we filter this to only page related ACF Field Groups? - */ - $field_groups = acf_get_field_groups(); - - /** - * We only want to add field groups for page type and template params. - * Page by location is already covered by `add_acf_fields_to_individual_posts`, - * so we do not want to duplicate that. - */ - $allowed_page_params = [ - 'page_type', - 'page_template', - ]; - - foreach ( $field_groups as $field_group ) { - if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { - foreach ( $field_group['location'] as $locations ) { - if ( ! empty( $locations ) && is_array( $locations ) ) { - foreach ( $locations as $location ) { - - /** - * If the operator is not equal to, we don't need to do anything, - * so we can just continue - */ - if ( '!=' === $location['operator'] ) { - continue; - } - - /** - * Add field group if the param is page related. - */ - if ( in_array( $location['param'], $allowed_page_params, true ) && '==' === $location['operator'] ) { - $page_field_groups[] = [ - 'type' => $location['param'], - 'field_group' => $field_group, - 'post_id' => $location['value'] - ]; - } - } - } - } - } - } - - - /** - * If no field groups are assigned to pages, we don't need to modify the Schema. - */ - if ( empty( $page_field_groups ) ) { - return; - } - - /** - * Loop over the field groups assigned to pages - * and register them to the Schema - */ - foreach ( $page_field_groups as $key => $group ) { - - if ( empty( $group['field_group'] ) || ! is_array( $group['field_group'] ) ) { - continue; - } - - // Initialize our field group object. - $field_group = $group['field_group']; - - $page_type_object = get_post_type_object('page'); - - $field_name = isset( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : Config::camel_case( $field_group['title'] ); - $field_group['type'] = 'group'; - $field_group['name'] = $field_name; - $description = $field_group['description'] ? $field_group['description'] . ' | ' : ''; - $config = [ - 'name' => $field_name, - 'description' => $description, - 'acf_field' => $field_group, - 'acf_field_group' => null, - 'resolve' => function( $root ) use ( $field_group ) { - return isset( $root ) ? $root : null; - } - ]; - - $this->register_graphql_field($page_type_object->graphql_single_name, $field_name, $config); - - } - } }