Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am using exposed filters for a CSV export, and then providing the URL via an email daily.
For instance:
The Data Export path is:
/admin/orders/payment-list-all.csv
With exposed filters the path becomes something like:
/admin/orders/payment-list-all.csv?created_between[min]=2011-09-22&created_between[max]=2011-09-23
Now this works, however it always spits out the same filename. I think it would be very useful to set the filename with tokens based on the exposed filter values such as:
payment-list-all-[created_between:min].csv
Comment | File | Size | Author |
---|---|---|---|
#5 | step-3.png | 19.69 KB | aniket.mohite88 |
#5 | step-2.png | 17.72 KB | aniket.mohite88 |
#5 | step-1.png | 13.28 KB | aniket.mohite88 |
Comments
Comment #1
R.Hendel CreditAttribution: R.Hendel commentedIt would be fantastic, if there would be an option to use also arguments in the file name.
Comment #2
ultimikeSee this comment for the proper way to do this.
-mike
Comment #3
xurizaemonComment #5
aniket.mohite88 CreditAttribution: aniket.mohite88 commentedHi,
Its a good point mentioned here in this comment.
I have used the below method to generate static or dynamic file-names while exporting.
--------------------------------------------------------------------------------------------
STATIC FILENAME
Step-1: Setting for the exported file
Step-2: Select "provide as file" & mention a filename
Step-3: Choose from replacement pattern tokens
--------------------------------------------------------------------------------------------
DYNAMIC FILENAME
To have a custom dynamic file name, you have to use the hook_views_pre_build(&$view) hook in your custom module.
You can have your custom calculations or get data from exposed filters & change the file-name dynamically using -
$view->display_handler->options['style_options']['filename'] = $file;
NOTE- Since you are altering the file-name dynamically, you have to first mention a static file-name as mentioned in above section.
example usage -
The above code will work & alter the file-name every time a filter is applied (filter value is changed).
Hope this helps.
Regards,
Aniket Mohite
Comment #6
arunkumarkThanks for comment #5 for dynamic file name change by coding.
The below code helps to change the file name in hook_views_post_execute().
The dynamic file name needs to pass for the argument.
$view->style_plugin->options['filename'] = 'NEW_FILENAME' . $nid;