summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/views/modules/system/views_handler_field_file_filemime.inc
blob: 0b29c79a232891d9d142152051e1c9b67ad3b6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

/**
 * Field handler to add rendering MIME type images as an option on the filemime field.
 *
 * @ingroup views_field_handlers
 */
class views_handler_field_file_filemime extends views_handler_field_file {
  function option_definition() {
    $options = parent::option_definition();
    $options['filemime_image'] = array('default' => FALSE);
    return $options;
  }

  function options_form(&$form, &$form_state) {
    $form['filemime_image'] = array(
      '#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['filemime_image']),
    );
    parent::options_form($form, $form_state);
  }

  function render($values) {
    $data = $values->{$this->field_alias};
    if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') {
      $fake_file = (object) array('filemime' => $data);
      $data = theme('file_icon', array('file' => $fake_file));
    }

    return $this->render_link($data, $values);
  }
}