1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_file_link.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to present a link to the file.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_file_link extends views_handler_field_entity {
|
14
|
|
15
|
function option_definition() {
|
16
|
$options = parent::option_definition();
|
17
|
$options['text'] = array('default' => '', 'translatable' => TRUE);
|
18
|
return $options;
|
19
|
}
|
20
|
|
21
|
function options_form(&$form, &$form_state) {
|
22
|
$form['text'] = array(
|
23
|
'#type' => 'textfield',
|
24
|
'#title' => t('Text to display'),
|
25
|
'#default_value' => $this->options['text'],
|
26
|
);
|
27
|
parent::options_form($form, $form_state);
|
28
|
|
29
|
// The path is set by render_link function so don't allow to set it.
|
30
|
$form['alter']['path'] = array('#access' => FALSE);
|
31
|
$form['alter']['external'] = array('#access' => FALSE);
|
32
|
}
|
33
|
|
34
|
function render($values) {
|
35
|
if ($entity = $this->get_value($values)) {
|
36
|
return $this->render_link($entity, $values);
|
37
|
}
|
38
|
}
|
39
|
|
40
|
function render_link($file, $values) {
|
41
|
if (file_entity_access('view', $file)) {
|
42
|
$this->options['alter']['make_link'] = TRUE;
|
43
|
$this->options['alter']['path'] = "file/$file->fid";
|
44
|
$text = !empty($this->options['text']) ? $this->options['text'] : t('View');
|
45
|
return $text;
|
46
|
}
|
47
|
}
|
48
|
}
|