Don't put "view-" in default export filename

Aren Cambre - July 1, 2009 - 01:02
Project:Views Bonus Pack
Version:6.x-1.x-dev
Component:Views Export
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

The default filename on Views Export uses view-%view.[extension]. This is a variation of the mostly discredited Hungarian notation.

Suggest just using %view.[extension] instead.

#1

neclimdul - July 22, 2009 - 23:23

I haven't responded to this but I should comment and say I'm not ignoring this but I just haven't decided what the right answer is. Patches and discussion are welcome.

#2

Aren Cambre - July 23, 2009 - 01:29

I think %view.[extension] would be fine. What do you think?

#3

sin.star - August 5, 2009 - 13:12

Despite of the fact that I'd prefer Arens version, I'd like to have more options. For example I use the standard taxonomy_term view and would like the user to be able to download a file containing all stories for a given term. Instead of having the downloaded file named (view-)taxonomy_term.(doc|xls|...), I'd like to insert the argument as part of the title, for example given the term 'sport' the downloadable file should be called sport.doc or taxonomy_term-sport.doc (by using a pattern like %arg[0].[extension] or %view-%arg[0].[extension].

I figured the change in code should be in views_bonus_export.theme.inc within the function _views_bonus_export_shared_preprocess, but I don't have a clue, which variables are available in $vars.

#4

sin.star - August 5, 2009 - 14:24

While playing around a bit I came across following solution for my problem.

Changing line 93 in views_bonus_export.theme.inc from:

array('%view' => check_plain($view->name))

to

array('%view' => check_plain($view->name), '%arg0' => check_plain($view->args[0]))

makes %arg0 available in filename und uses the first argument passed to this view. Adding more argument vars is of course possible by adding more items to the above array.

#5

Aren Cambre - August 5, 2009 - 15:03

How about tokens using the Token module?

#6

sin.star - August 7, 2009 - 10:22

Sounds like a good idea as far as how much I know about the Token module which is, well kind of nothing. For now I have changed the relevant part in the filename function to the following, enabling all given arguments, the view name as well as the current date to be used in the filename:

  $filename_options = array('%view' => check_plain($view->name), '%date' => date('Ymd',time()));
  $args = $view->args;
  foreach ( $args AS $key => $val )
  {
    $filename_options['%arg'.$key] = check_plain($val);
  }
  $filename = strtr(
    $vars['options']['filename'],
    $filename_options
  );

So, in my case the doc file for the taxonomy term view of 'sport' uses the dynamic filename %view-%arg0_%date.doc which results in taxonomy_term-sport_20090807.doc.

#7

neclimdul - August 7, 2009 - 17:24

Sorry to disrupt but lets make token support a different issue. This is distracting from whether we should ax the Hungarian notation used in the default file name.

 
 

Drupal is a registered trademark of Dries Buytaert.