-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CSV export issue #2215 #2216
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,66 @@ | |
/** | ||
* The default field output template for CSVs. | ||
* | ||
* @global \GV\Template_Context $gravityview | ||
* @since 2.0 | ||
* @global Template_Context $gravityview | ||
*/ | ||
|
||
use GV\Template_Context; | ||
use GV\Utils; | ||
|
||
if ( ! isset( $gravityview ) || empty( $gravityview->template ) ) { | ||
gravityview()->log->error( '{file} template loaded without context', array( 'file' => __FILE__ ) ); | ||
|
||
return; | ||
} | ||
|
||
$field_id = $gravityview->field->ID; | ||
$display_value = $gravityview->display_value; | ||
$value = $gravityview->value; | ||
$entry = $gravityview->entry->as_entry(); | ||
$field_id = $gravityview->field->ID; | ||
$field = $gravityview->field->field; | ||
$value = $gravityview->value; | ||
$form = $gravityview->view->form->form; | ||
$entry = $gravityview->entry->as_entry(); | ||
$field_settings = $gravityview->field->as_configuration(); | ||
$display_type = Utils::get( $field_settings, 'choice_display' ); | ||
$is_single_input = floor( $field_id ) !== floatval( $field_id ); | ||
$output = ''; | ||
|
||
/** | ||
* The value used to separate multiple values in the CSV export. | ||
* | ||
* @since 2.4.2 | ||
* | ||
* @param string The glue. Default: ";" (semicolon) | ||
* @param \GV\Template_Context The context. | ||
*/ | ||
$glue = apply_filters( 'gravityview/template/field/csv/glue', ';', $gravityview ); | ||
// It's the parent field, not an input | ||
if ( ! $is_single_input ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mrcasual This is the same logic as in the |
||
/** | ||
* The value used to separate multiple values in the CSV export. | ||
* | ||
* @since 2.4.2 | ||
* | ||
* @param string $glue The glue. Default: ";" (semicolon). | ||
* @param Template_Context $gravityview The context. | ||
*/ | ||
$glue = apply_filters( 'gravityview/template/field/csv/glue', ';', $gravityview ); | ||
$output = implode( $glue, array_filter( $value ) ); | ||
} else { | ||
|
||
$field_value = $entry[ $field_id ] ?? ''; | ||
|
||
switch ( $display_type ) { | ||
case 'label': | ||
$output = gravityview_get_field_label( $form, $field_id, $value ); | ||
break; | ||
case 'tick': | ||
default: | ||
if ( $field_value ) { | ||
/** | ||
* Change the output for a checkbox "check" symbol. | ||
* | ||
* @since $ver$ | ||
* | ||
* @param string $output Checkbox "check" symbol. Default: "✓". | ||
* @param array $entry Entry data. | ||
* @param GF_Field_Checkbox $field GravityView field. | ||
* @param Template_Context $gravityview The context. | ||
*/ | ||
$output = apply_filters( 'gravityview/template/field/csv/tick', '✓', $entry, $field, $gravityview ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zahardev, is there a reason why you didn't use the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mrcasual The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification @zahardev! @mrcasual that explains why DataTables wasn't able to export the ticks (DT strips HTML), and I had to use an emoji in place: https://github.com/GravityKit/DataTables/issues/60#issuecomment-856311493 |
||
} | ||
break; | ||
} | ||
} | ||
|
||
echo implode( $glue, array_filter( $value ) ); | ||
echo $output; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrcasual This was the cause of the bug - it always used the main form as the source, even when the field belonged to the joined form.