~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to sites/all/modules/views/modules/system/views_handler_field_file.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: views_handler_field_file.inc,v 1.3 2009/01/30 00:01:42 merlinofchaos Exp $
 
3
/**
 
4
 * Field handler to provide simple renderer that allows linking to a file.
 
5
 */
 
6
class views_handler_field_file extends views_handler_field {
 
7
  /**
 
8
   * Constructor to provide additional field to add.
 
9
   */
 
10
  function init(&$view, &$options) {
 
11
    parent::init($view, $options);
 
12
    if (!empty($options['link_to_file'])) {
 
13
      $this->additional_fields['filepath'] = 'filepath';
 
14
    }
 
15
  }
 
16
 
 
17
  function option_definition() {
 
18
    $options = parent::option_definition();
 
19
    $options['link_to_file'] = array('default' => FALSE);
 
20
    return $options;
 
21
  }
 
22
 
 
23
  /**
 
24
   * Provide link to file option
 
25
   */
 
26
  function options_form(&$form, &$form_state) {
 
27
    parent::options_form($form, $form_state);
 
28
    $form['link_to_file'] = array(
 
29
      '#title' => t('Link this field to download the file'),
 
30
      '#description' => t('This will override any other link you have set.'),
 
31
      '#type' => 'checkbox',
 
32
      '#default_value' => !empty($this->options['link_to_file']),
 
33
    );
 
34
  }
 
35
 
 
36
  /**
 
37
   * Render whatever the data is as a link to the file.
 
38
   *
 
39
   * Data should be made XSS safe prior to calling this function.
 
40
   */
 
41
  function render_link($data, $values) {
 
42
    if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
 
43
      $this->options['alter']['make_link'] = TRUE;
 
44
      $this->options['alter']['path'] = file_create_url($values->{$this->aliases['filepath']});
 
45
    }
 
46
 
 
47
    return $data;
 
48
  }
 
49
 
 
50
  function render($values) {
 
51
    return $this->render_link(check_plain($values->{$this->field_alias}), $values);
 
52
  }
 
53
}