Skip to content

Commit

Permalink
Fixes reversing issue (#2157)
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
mrcasual authored Oct 14, 2024
2 parents d171c2e + 209c90f commit f593e47
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions includes/fields/class-gravityview-field-survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ public static function get_choice_score( $field, $value, $input_id = 0 ) {
return is_array( $value ) ? '' : $value;
}

/**
* Gets field choices directly from the database (To avoid issues where choices are reversed by the survey plugin).
*
* @since TBD
*
* @param int $form_id The ID of the form.
* @param int $field_id The ID of the field.
*
* @return array The choices for the field.
*/
public static function get_field_choices($form_id, $field_id) {
global $wpdb;
$table_name = GFFormsModel::get_meta_table_name();
$form_row = $wpdb->get_row( $wpdb->prepare( "SELECT display_meta FROM {$table_name} WHERE form_id=%d", $form_id ), ARRAY_A );
$form_meta = GFFormsModel::unserialize( rgar( $form_row, 'display_meta' ) );

if ( ! $form_meta ) {
return [];
}

foreach ( $form_meta['fields'] as $form_field ) {
if ( $form_field['id'] == $field_id ) {
return $form_field['choices'];
}
}

return [];
}


public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {

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

= 2.29 on October 1, 2024 =

Expand Down
4 changes: 3 additions & 1 deletion templates/fields/field-survey-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$field = $gravityview->field;
$display_value = $gravityview->display_value;
$input_id = gravityview_get_input_id_from_id( $field->ID );
$form_id = $gravityview->view->form->ID;

// Used in filters below.
$return_true = function () {
Expand Down Expand Up @@ -142,7 +143,8 @@
return;
}

$choices = $field->field->choices;
$choices = GravityView_Field_Survey::get_field_choices( $form_id, $field->ID );

$choice_values = wp_list_pluck( $choices, 'value', $gravityview->value );
$starred_index = array_search( $gravityview->value, $choice_values );
$star_a11y_label = $starred_index !== false
Expand Down

0 comments on commit f593e47

Please sign in to comment.