From 486d9b3afeefd0daf7e9f1f5d2b4f16573ee5521 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sun, 4 Feb 2024 01:57:32 +0200 Subject: [PATCH] fix: ensure `EmailField` inputs are hydrated when Email Confirmation is disabled. (#394) --- CHANGELOG.md | 3 +++ src/Type/WPInterface/FieldWithInputs.php | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c09399..ce039b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- fix: Ensure `EmailField` inputs are hydrated when Email Confirmation is disabled. H/t @ +Gytjarek. + ## v0.12.4 This _minor_ release fixes a bug where updating the plugin via the WordPress backend would fail due to changes to GitHub's API. diff --git a/src/Type/WPInterface/FieldWithInputs.php b/src/Type/WPInterface/FieldWithInputs.php index 84296683..d69280d0 100644 --- a/src/Type/WPInterface/FieldWithInputs.php +++ b/src/Type/WPInterface/FieldWithInputs.php @@ -37,11 +37,26 @@ public static function get_fields(): array { 'inputs' => [ 'type' => [ 'list_of' => FieldInput::$type ], 'description' => __( 'The inputs for the field.', 'wp-graphql-gravity-forms' ), - 'resolve' => static function ( $source, array $args, AppContext $context, $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { + // Email fields without confirmation need to be coerced as an input. + if ( $source instanceof \GF_Field_Email && ! $source->emailConfirmEnabled ) { + $source->inputs = [ + [ + 'autocompleteAttribute' => $source->autocompleteAttribute ?? null, + 'defaultValue' => $source->defaultValue ?? null, + 'customLabel' => $source->customLabel ?? null, + 'id' => $source->id ?? null, + 'label' => $source->label ?? null, + 'name' => $source->inputName ?? null, + 'placeholder' => $source->placeholder ?? null, + ], + ]; + } + /** @var \GF_Field $source */ $context->gfField = $source; - return ! empty( $source->inputs ) + return isset( $source->inputs ) // Include GraphQL Type in resolver. ? array_map( static function ( $choice ) use ( $source ) {