Skip to content

Commit f593e47

Browse files
authored
Fixes reversing issue (#2157)
- Fixes #2125 - The issue was only happening if a gravity forms field is put before gravity view field - And that was happening because of a logic inside the survey plugin that was reversing the field choices for some reason that was being called when a gravity form is embedded in a page so it was affecting anything that comes after it that depend on field choices - ![image](https://github.com/user-attachments/assets/b51dc843-846e-4303-8971-96085e0a8095) 💾 [Build file](https://www.dropbox.com/scl/fi/tq5b88padqzsf7rb2j5p8/gravityview-2.29-9e98a5f8c.zip?rlkey=zgkkplicdpgg2cbg5xeng5u5h&dl=1) (9e98a5f).
2 parents d171c2e + 209c90f commit f593e47

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

includes/fields/class-gravityview-field-survey.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ public static function get_choice_score( $field, $value, $input_id = 0 ) {
5959
return is_array( $value ) ? '' : $value;
6060
}
6161

62+
/**
63+
* Gets field choices directly from the database (To avoid issues where choices are reversed by the survey plugin).
64+
*
65+
* @since TBD
66+
*
67+
* @param int $form_id The ID of the form.
68+
* @param int $field_id The ID of the field.
69+
*
70+
* @return array The choices for the field.
71+
*/
72+
public static function get_field_choices($form_id, $field_id) {
73+
global $wpdb;
74+
$table_name = GFFormsModel::get_meta_table_name();
75+
$form_row = $wpdb->get_row( $wpdb->prepare( "SELECT display_meta FROM {$table_name} WHERE form_id=%d", $form_id ), ARRAY_A );
76+
$form_meta = GFFormsModel::unserialize( rgar( $form_row, 'display_meta' ) );
77+
78+
if ( ! $form_meta ) {
79+
return [];
80+
}
81+
82+
foreach ( $form_meta['fields'] as $form_field ) {
83+
if ( $form_field['id'] == $field_id ) {
84+
return $form_field['choices'];
85+
}
86+
}
87+
88+
return [];
89+
}
90+
91+
6292
public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
6393

6494
unset( $field_options['search_filter'] );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
3131
* Fixed: Resending notifications from the Entries screen did not work when sending to all entries filtered by approval status.
3232
* Fixed: Conflict with the Wordfence plugin caused a fatal error when redirecting users after deleting an entry.
3333
* Fixed: Fatal error when rendering a GravityView View field with a non-existent View ID.
34+
* Fixed: Survey field (Rating type) values displaying in reverse order when a View is embedded inside another View.
3435

3536
= 2.29 on October 1, 2024 =
3637

templates/fields/field-survey-html.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
$field = $gravityview->field;
1616
$display_value = $gravityview->display_value;
1717
$input_id = gravityview_get_input_id_from_id( $field->ID );
18+
$form_id = $gravityview->view->form->ID;
1819

1920
// Used in filters below.
2021
$return_true = function () {
@@ -142,7 +143,8 @@
142143
return;
143144
}
144145

145-
$choices = $field->field->choices;
146+
$choices = GravityView_Field_Survey::get_field_choices( $form_id, $field->ID );
147+
146148
$choice_values = wp_list_pluck( $choices, 'value', $gravityview->value );
147149
$starred_index = array_search( $gravityview->value, $choice_values );
148150
$star_a11y_label = $starred_index !== false

0 commit comments

Comments
 (0)