Skip to content

Commit

Permalink
Fix CSV export for /view/{view_slug}/csv/ URL #2215
Browse files Browse the repository at this point in the history
  • Loading branch information
zahardev committed Nov 26, 2024
1 parent 4734287 commit 6603f79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
35 changes: 34 additions & 1 deletion future/includes/class-gv-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,39 @@ public static function by_id( $post_id ) {
return self::from_post( $post );
}

/**
* Gets the source of the field.
*
* @since $ver$
*
* @param Field $field The field.
* @param View $view The view.
*
* @return GF_Form|Internal_Source
*/
public static function get_source( $field, $view ) {
if ( ! is_numeric( $field->ID ) ) {
return new Internal_Source();
}

$form_id = $field->field->formId ?? null;

// If the field's form differs from the main view form, get the form from the joined entries.
if ( $form_id && $view->form->ID != $form_id && ! empty( $view->joins ) ) {
foreach ( $view->joins as $join ) {
if ( isset( $join->join_on->ID ) && $join->join_on->ID == $form_id ) {
return $join->join_on;
}
}

// Edge case where the form cannot be retrieved from the joins.
return GF_Form::by_id( $form_id );
}

// Return the main view form.
return $view->form;
}

/**
* Determines if a view exists to begin with.
*
Expand Down Expand Up @@ -1691,7 +1724,7 @@ function ( $field ) use ( $allowed_field_ids ) {
}

foreach ( $allowed as $field ) {
$source = is_numeric( $field->ID ) ? $view->form : new \GV\Internal_Source();
$source = self::get_source( $field, $view );

$return[] = $renderer->render( $field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template' );

Expand Down
35 changes: 1 addition & 34 deletions future/includes/rest/class-gv-rest-views-route.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function ( $field ) use ( $allowed_field_ids ) {
// remove all links from output.
$field->update_configuration( [ 'show_as_link' => '0' ] );

$source = $this->get_source( $field, $view );
$source = View::get_source( $field, $view );

$field_id = $field->ID;
$index = null;
Expand Down Expand Up @@ -245,39 +245,6 @@ function ( $field ) use ( $allowed_field_ids ) {
return $return;
}

/**
* Gets the source of the field.
*
* @since $ver$
*
* @param Field $field The field.
* @param View $view The view.
*
* @return GF_Form|Internal_Source
*/
protected function get_source( $field, $view ) {
if ( ! is_numeric( $field->ID ) ) {
return new Internal_Source();
}

$form_id = $field->field->formId ?? null;

// If the field's form differs from the main view form, get the form from the joined entries.
if ( $form_id && $view->form->ID != $form_id && ! empty( $view->joins ) ) {
foreach ( $view->joins as $join ) {
if ( isset( $join->join_on->ID ) && $join->join_on->ID == $form_id ) {
return $join->join_on;
}
}

// Edge case where the form cannot be retrieved from the joins.
return GF_Form::by_id( $form_id );
}

// Return the main view form.
return $view->form;
}

/**
* Get entries from a view
*
Expand Down

0 comments on commit 6603f79

Please sign in to comment.