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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul’s picture

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.

Aren Cambre’s picture

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

broon’s picture

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.

broon’s picture

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.

Aren Cambre’s picture

How about tokens using the Token module?

broon’s picture

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.

neclimdul’s picture

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.

dboulet’s picture

Status: Needs review » Active
FileSize
3.88 KB

This patch changes the file name defaults. Discussions on adding more replacement options can continue in the following threads:

#686348: Token support for file export
#411392: Variables in filenames
#702180: Use more tokens in file name
#732930: Ability to add current date to filename

dboulet’s picture

Status: Active » Needs review
doublejosh’s picture

Status: Active » Needs review

How be the patch?

broon’s picture

The patch in #8 just removes the string "view-" from default file names. But dboulet provides links to other issues where some patches à la dboulet are to be found.

I actually applied the date and the token patches (combined them) and they work like a charm. ;) Thanks for that dboulet!