Projet

Général

Profil

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

root / drupal7 / sites / all / modules / file_entity / views / views_handler_field_file_filename.inc @ 66c11afc

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_file_filename.
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_filename extends views_handler_field_file {
14
  /**
15
   * Constructor to provide additional field to add.
16
   */
17
  function init(&$view, &$options) {
18
    if (!empty($this->options['link_to_file'])) {
19
      $this->additional_fields['fid'] = 'fid';
20
    }
21
    parent::init($view, $options);
22
  }
23

    
24
  function option_definition() {
25
    $options = parent::option_definition();
26
    $options['link_to_file'] = array('default' => TRUE, 'bool' => TRUE);
27
    return $options;
28
  }
29

    
30
  /**
31
   * Provide link to file option
32
   */
33
  function options_form(&$form, &$form_state) {
34
    parent::options_form($form, $form_state);
35
    $form['link_to_file']['#title'] = t('Link this field to the original file');
36
  }
37

    
38
  /**
39
   * Render whatever the data is as a link to the file.
40
   *
41
   * Data should be made XSS safe prior to calling this function.
42
   */
43
  function render_link($data, $values) {
44
    if (!empty($this->options['link_to_file']) && !empty($this->additional_fields['fid'])) {
45
      if ($data !== NULL && $data !== '') {
46
        $this->options['alter']['make_link'] = TRUE;
47
        $this->options['alter']['path'] = 'file/' . $this->get_value($values, 'fid');
48
      }
49
    }
50
    return $data;
51
  }
52
}