Skip to content

Commit

Permalink
Add force download hook
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Oct 28, 2024
1 parent 85ea5ac commit 55cf4d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.gravitykit.com/extensions/gravityexport/?utm_source=plu
Tags: Gravity Forms, GravityForms, Excel, Export, Entries
Requires at least: 4.0
Requires PHP: 7.2
Tested up to: 6.6.2
Tested up to: 6.7
Stable tag: 2.3.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -256,6 +256,10 @@ You can hide a row by adding a hook. Checkout this example:

== Changelog ==

= develop =

* Enhancement: Added `gfexcel_field_fileuploads_force_download` hook, to disable the forced download links.

= 2.3.2 on October 14, 2024 =

* Fixed: Added compatibility for servers that miss the `iconv` or `mbstring` PHP extension.
Expand Down
26 changes: 23 additions & 3 deletions src/Field/FileUploadField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Class FileUploadField
*
* @since 1.1.0
*/
class FileUploadField extends BaseField implements RowsInterface {
Expand Down Expand Up @@ -51,7 +52,6 @@ public function getColumns() {
* @return bool Whether the uploads should be shown as a column.
*/
private function showFileUploadsAsColumn() {

// The default value of `true` will not be returned by get_plugin_setting(); it will return null by default.
// So we apply the ?? operator and return true as the default value.
$fileuploads_enabled = GravityExportAddon::get_instance()->get_plugin_setting( 'fileuploads_enabled' ) ?? true;
Expand Down Expand Up @@ -80,7 +80,9 @@ public function getRows( ?array $entry = null ): iterable {
}

foreach ( $files as $file ) {
yield $this->wrap( [ $this->field->get_download_url( $file, true ) ] );
yield $this->wrap( [
$this->field->get_download_url( $file, $this->should_force_download() ),
] );
}
}
} else {
Expand All @@ -98,6 +100,24 @@ protected function getFieldValue( $entry, $input_id = '' ) {
return $value;
}

return $this->field->get_download_url( $value, true );
return $this->field->get_download_url( $value, $this->should_force_download() );
}

/**
* Returns whether to force a download URL.
*
* @since $ver$
*
* @return bool Whether to force a download URL.
*/
private function should_force_download(): bool {
return (bool) gf_apply_filters(
[
'gfexcel_field_fileuploads_force_download',
$this->field->formId,
],
true,
$this->field
);
}
}

0 comments on commit 55cf4d5

Please sign in to comment.