Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
release 1.10.4

Closes #56

See merge request luminfire/products/gravity-integrations/field-helper-for-gravity-forms!99
  • Loading branch information
andrewminion-luminfire committed Oct 30, 2024
2 parents 4495b17 + baad882 commit 3deb1df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
47 changes: 24 additions & 23 deletions class-gf-field-helper-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public static function replace_field_names( $result ) {
$original_entry = $result;

foreach ( $result as $key => $value ) {
$sanitized_key = self::convert_field_id( $key );
$field_id = self::convert_field_id( $key );
$field_and_form_id = self::convert_field_id( $key, $result['form_id'] );

if ( array_key_exists( $field_and_form_id, self::$checkbox_fields ) ) {
// Checkbox.
if ( ! empty( $value ) ) {
$fields[ $labels[ absint( $sanitized_key ) ] ][] = $value;
$fields[ $labels[ $field_id ] ][] = $value;
}
} elseif ( array_key_exists( $field_and_form_id, self::$nested_fields ) ) {
// Nested Form field.
Expand All @@ -147,47 +147,47 @@ public static function replace_field_names( $result ) {
);
}
foreach ( $entries as $nested_entry ) {
$fields[ $labels[ absint( $sanitized_key ) ] ][] = self::replace_field_names( $nested_entry );
$fields[ $labels[ $field_id ] ][] = self::replace_field_names( $nested_entry );
}
break;

case 'array':
if ( is_array( $value ) ) {
$value = wp_list_pluck( $value, 'id' );
}
$value = json_decode( '[' . $value . ']' );
$fields[ $labels[ absint( $sanitized_key ) ] ] = $value;
$value = json_decode( '[' . $value . ']' );
$fields[ $labels[ $field_id ] ] = $value;
break;

case 'csv':
default:
if ( is_array( $value ) ) {
$value = wp_list_pluck( $value, 'id' );
}
$fields[ $labels[ absint( $sanitized_key ) ] ] = $value;
$fields[ $labels[ $field_id ] ] = $value;
break;
}
}
} elseif ( array_key_exists( $field_and_form_id, self::$signature_fields ) ) {
if ( self::$signature_fields[ $field_and_form_id ] === 'url' ) {
$field = GFAPI::get_field( $result['form_id'], absint( $sanitized_key ) );
$fields[ $labels[ $sanitized_key ] ] = $field->get_value_url( $value );
$field = GFAPI::get_field( $result['form_id'], $field_id );
$fields[ $labels[ $field_id ] ] = $field->get_value_url( $value );
} else {
$fields[ $labels[ $sanitized_key ] ] = $value;
$fields[ $labels[ $field_id ] ] = $value;
}
} elseif ( array_key_exists( $sanitized_key, self::$survey_fields ) ) {
$field = GFAPI::get_field( $result ['form_id'], absint( $sanitized_key ) );
} elseif ( array_key_exists( $field_id, self::$survey_fields ) ) {
$field = GFAPI::get_field( $result ['form_id'], $field_id );
if ( method_exists( $field, 'get_column_text' ) ) {
/** @var GF_Field_Likert $field */ // phpcs:ignore, @phpstan-ignore-line
$fields[ $labels[ $sanitized_key ] ] = $field->get_column_text( $value, $original_entry, $key ); // @phpstan-ignore-line
/** @var \GF_Field_Likert $field */ // phpcs:ignore
$fields[ $labels[ $field_id ] ] = $field->get_column_text( $value, $original_entry, $key );
} elseif ( in_array( $field['inputType'], array( 'checkbox', 'select', 'radio' ), true ) ) {
$fields[ $labels[ $sanitized_key ] ] = $field->get_selected_choice( $value )['text'];
$fields[ $labels[ $field_id ] ] = $field->get_selected_choice( $value )['text'];
} else {
$fields[ $labels[ $sanitized_key ] ] = $field->get_value_export( $original_entry, $sanitized_key );
$fields[ $labels[ $field_id ] ] = $field->get_value_export( $original_entry, $field_id );
}
} elseif ( in_array( $sanitized_key, array_flip( $labels ), false ) ) { // phpcs:ignore WordPress.PHP.StrictInArray -- since GF uses both integer and string field keys.
} elseif ( in_array( $field_id, array_flip( $labels ), false ) ) { // phpcs:ignore WordPress.PHP.StrictInArray -- since GF uses both integer and string field keys.
// Others.
$fields[ $labels[ $sanitized_key ] ] = $value;
$fields[ $labels[ $field_id ] ] = $value;
}

// Unset only field keys (strings will convert to 0, floats to integers).
Expand Down Expand Up @@ -237,9 +237,10 @@ public static function get_form_friendly_labels( $form_id ) {
$fields = array_filter( $form[ GF_FIELD_HELPER_SLUG ] );

foreach ( $form['fields'] as $field ) {
$field_id = self::convert_field_id( $field['id'] );
$field_and_form_id = self::convert_field_id( $field['id'], $form_id );

if ( 'checkbox' === $field['type'] && array_key_exists( $field['id'] . '-checkbox-return', $fields ) && 'combined' === $fields[ $field['id'] . '-checkbox-return' ] ) {
if ( 'checkbox' === $field['type'] && array_key_exists( $field_id . '-checkbox-return', $fields ) && 'combined' === $fields[ $field_id . '-checkbox-return' ] ) {

// Unset the choices.
foreach ( $field['inputs'] as $input_key => $input_id ) {
Expand All @@ -252,12 +253,12 @@ public static function get_form_friendly_labels( $form_id ) {
self::$checkbox_fields[ $field_and_form_id ] = $field['id'];
}

if ( 'signature' === $field['type'] && array_key_exists( $field['id'] . '-signature-return', $fields ) ) {
self::$signature_fields[ $field_and_form_id ] = $fields[ $field['id'] . '-signature-return' ];
if ( 'signature' === $field['type'] && array_key_exists( $field_id . '-signature-return', $fields ) ) {
self::$signature_fields[ $field_and_form_id ] = $fields[ $field_id . '-signature-return' ];
}

if ( 'form' === $field['type'] && array_key_exists( $field['id'] . '-form-return', $fields ) ) {
self::$nested_fields[ $field_and_form_id ] = $fields[ $field['id'] . '-form-return' ];
if ( 'form' === $field['type'] && array_key_exists( $field_id . '-form-return', $fields ) ) {
self::$nested_fields[ $field_and_form_id ] = $fields[ $field_id . '-form-return' ];
}

if ( 'survey' === $field['type'] ) {
Expand All @@ -268,7 +269,7 @@ public static function get_form_friendly_labels( $form_id ) {
self::$survey_fields[ $input_id ] = $input_id;
}
} else {
self::$survey_fields[ $field_and_form_id ] = $fields[ $field['id'] ];
self::$survey_fields[ $field_and_form_id ] = $fields[ $field_and_form_id ];
}
}

Expand Down
4 changes: 4 additions & 0 deletions documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# 1.10.4 | 2024-10-30

- Bugfix: fix empty values for more advanced fields caused by 1.10.3

# 1.10.3 | 2024-10-25

- Bugfix: fix friendly field name settings being mangled by a change in Gravity Forms core
Expand Down
6 changes: 3 additions & 3 deletions field-helper-for-gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Field Helper for Gravity Forms
* Plugin URI: https://brilliantplugins.com/
* Description: Enables Gravity Forms users to set consistent, human-friendly field names for use in the Gravity Forms REST API.
* Version: 1.10.3
* Version: 1.10.4
* Author: BrilliantPlugins
* Author URI: https://brilliantplugins.com
* License: GPL-2.0+
Expand All @@ -30,7 +30,7 @@
* @package brilliant-plugins/field-helper-for-gravity-forms
*/

define( 'GF_FIELD_HELPER_VERSION', '1.10.3' );
define( 'GF_FIELD_HELPER_VERSION', '1.10.4' );
define( 'GF_FIELD_HELPER_FILE', __FILE__ );
define( 'GF_FIELD_HELPER_SLUG', 'gravity-forms-field-helper' );

Expand Down Expand Up @@ -130,6 +130,6 @@ public static function register_api_endpoint() {
*
* @return GF_Field_Helper Instance of GF Field Helper.
*/
function gf_field_helper() {
function gf_field_helper() { // phpcs:ignore -- Universal.Files.SeparateFunctionsFromOO.Mixed
return GF_Field_Helper::get_instance();
}
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: luminfire, macbookandrew, brilliantplugins, nickciske, daverydan
Tags: forms, form entries, api, Gravity Forms, FileMaker, database, field names
Requires at least: 4.8
Tested up to: 6.2.2
Stable tag: 1.10.3
Stable tag: 1.10.4
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down

0 comments on commit 3deb1df

Please sign in to comment.