1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_file_filemime.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to add rendering MIME type images as an option on the filemime field.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_file_filemime extends views_handler_field_file {
|
14
|
function option_definition() {
|
15
|
$options = parent::option_definition();
|
16
|
$options['filemime_image'] = array('default' => FALSE, 'bool' => TRUE);
|
17
|
return $options;
|
18
|
}
|
19
|
|
20
|
function options_form(&$form, &$form_state) {
|
21
|
$form['filemime_image'] = array(
|
22
|
'#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'),
|
23
|
'#type' => 'checkbox',
|
24
|
'#default_value' => !empty($this->options['filemime_image']),
|
25
|
);
|
26
|
parent::options_form($form, $form_state);
|
27
|
}
|
28
|
|
29
|
function render($values) {
|
30
|
$data = $values->{$this->field_alias};
|
31
|
if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') {
|
32
|
$fake_file = (object) array('filemime' => $data);
|
33
|
$data = theme('file_icon', array('file' => $fake_file));
|
34
|
}
|
35
|
|
36
|
return $this->render_link($data, $values);
|
37
|
}
|
38
|
}
|