1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains the file view row style plugin.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugin which performs a file_view on the resulting object.
|
10
|
*
|
11
|
* Most of the code on this object is in the theme function.
|
12
|
*/
|
13
|
class views_plugin_row_file_view extends views_plugin_row {
|
14
|
// Basic properties that let the row style follow relationships.
|
15
|
var $base_table = 'file_managed';
|
16
|
var $base_field = 'fid';
|
17
|
|
18
|
// Stores the files loaded with pre_render.
|
19
|
var $files = array();
|
20
|
|
21
|
function option_definition() {
|
22
|
$options = parent::option_definition();
|
23
|
|
24
|
$options['view_mode'] = array('default' => 'default');
|
25
|
$options['links'] = array('default' => TRUE);
|
26
|
return $options;
|
27
|
}
|
28
|
|
29
|
function options_form(&$form, &$form_state) {
|
30
|
parent::options_form($form, $form_state);
|
31
|
|
32
|
$form['view_mode'] = array(
|
33
|
'#type' => 'select',
|
34
|
'#options' => file_entity_view_mode_labels(),
|
35
|
'#title' => t('View mode'),
|
36
|
'#default_value' => $this->options['view_mode'],
|
37
|
);
|
38
|
$form['links'] = array(
|
39
|
'#type' => 'checkbox',
|
40
|
'#title' => t('Display links'),
|
41
|
'#default_value' => $this->options['links'],
|
42
|
);
|
43
|
}
|
44
|
|
45
|
function summary_title() {
|
46
|
$view_mode_label = file_entity_view_mode_label($this->options['view_mode'], t('Unknown'));
|
47
|
return check_plain($view_mode_label);
|
48
|
}
|
49
|
|
50
|
function pre_render($values) {
|
51
|
$fids = array();
|
52
|
foreach ($values as $row) {
|
53
|
$fids[] = $row->{$this->field_alias};
|
54
|
}
|
55
|
$this->files = file_load_multiple($fids);
|
56
|
}
|
57
|
|
58
|
function render($row) {
|
59
|
$file = $this->files[$row->{$this->field_alias}];
|
60
|
$file->view = $this->view;
|
61
|
$build = file_view($file, $this->options['view_mode']);
|
62
|
|
63
|
return drupal_render($build);
|
64
|
}
|
65
|
}
|