commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / system / views_handler_field_file.inc
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 * Constructor to provide additional field to add.
16 */
17 function init(&$view, &$options) {
18 parent::init($view, $options);
19 if (!empty($options['link_to_file'])) {
20 $this->additional_fields['uri'] = 'uri';
21 }
22 }
23
24 function option_definition() {
25 $options = parent::option_definition();
26 $options['link_to_file'] = array('default' => FALSE, 'bool' => TRUE);
27 return $options;
28 }
29
30 /**
31 * Provide link to file option
32 */
33 function options_form(&$form, &$form_state) {
34 $form['link_to_file'] = array(
35 '#title' => t('Link this field to download the file'),
36 '#description' => t("Enable to override this field's links."),
37 '#type' => 'checkbox',
38 '#default_value' => !empty($this->options['link_to_file']),
39 );
40 parent::options_form($form, $form_state);
41 }
42
43 /**
44 * Render whatever the data is as a link to the file.
45 *
46 * Data should be made XSS safe prior to calling this function.
47 */
48 function render_link($data, $values) {
49 if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
50 $this->options['alter']['make_link'] = TRUE;
51 $this->options['alter']['path'] = file_create_url($this->get_value($values, 'uri'));
52 }
53
54 return $data;
55 }
56
57 function render($values) {
58 $value = $this->get_value($values);
59 return $this->render_link($this->sanitize_value($value), $values);
60 }
61 }