2
// $Id: views_handler_field_file.inc,v 1.3 2009/01/30 00:01:42 merlinofchaos Exp $
4
* Field handler to provide simple renderer that allows linking to a file.
6
class views_handler_field_file extends views_handler_field {
8
* Constructor to provide additional field to add.
10
function init(&$view, &$options) {
11
parent::init($view, $options);
12
if (!empty($options['link_to_file'])) {
13
$this->additional_fields['filepath'] = 'filepath';
17
function option_definition() {
18
$options = parent::option_definition();
19
$options['link_to_file'] = array('default' => FALSE);
24
* Provide link to file option
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']),
37
* Render whatever the data is as a link to the file.
39
* Data should be made XSS safe prior to calling this function.
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']});
50
function render($values) {
51
return $this->render_link(check_plain($values->{$this->field_alias}), $values);