Projet

Général

Profil

Paste
Télécharger (1,72 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / system / views_handler_field_file.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_file.
6
 */
7

    
8
/**
9
 * Field handler to provide simple renderer that allows linking to a file.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_file extends views_handler_field {
14

    
15
  /**
16
   * Constructor to provide additional field to add.
17
   */
18
  public function init(&$view, &$options) {
19
    parent::init($view, $options);
20
    if (!empty($options['link_to_file'])) {
21
      $this->additional_fields['uri'] = 'uri';
22
    }
23
  }
24

    
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function option_definition() {
29
    $options = parent::option_definition();
30
    $options['link_to_file'] = array('default' => FALSE, 'bool' => TRUE);
31
    return $options;
32
  }
33

    
34
  /**
35
   * Provide link to file option.
36
   */
37
  public function options_form(&$form, &$form_state) {
38
    $form['link_to_file'] = array(
39
      '#title' => t('Link this field to download the file'),
40
      '#description' => t("Enable to override this field's links."),
41
      '#type' => 'checkbox',
42
      '#default_value' => !empty($this->options['link_to_file']),
43
    );
44
    parent::options_form($form, $form_state);
45
  }
46

    
47
  /**
48
   * Render whatever the data is as a link to the file.
49
   *
50
   * Data should be made XSS safe prior to calling this function.
51
   */
52
  public function render_link($data, $values) {
53
    if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
54
      $this->options['alter']['make_link'] = TRUE;
55
      $this->options['alter']['path'] = file_create_url($this->get_value($values, 'uri'));
56
    }
57

    
58
    return $data;
59
  }
60

    
61
  /**
62
   * {@inheritdoc}
63
   */
64
  public function render($values) {
65
    $value = $this->get_value($values);
66
    return $this->render_link($this->sanitize_value($value), $values);
67
  }
68

    
69
}