Projet

Général

Profil

Paste
Télécharger (1,23 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / system / views_handler_field_file_filemime.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_file_filemime.
6
 */
7

    
8
/**
9
 * 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

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20
    $options['filemime_image'] = array('default' => FALSE, 'bool' => TRUE);
21
    return $options;
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function options_form(&$form, &$form_state) {
28
    $form['filemime_image'] = array(
29
      '#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'),
30
      '#type' => 'checkbox',
31
      '#default_value' => !empty($this->options['filemime_image']),
32
    );
33
    parent::options_form($form, $form_state);
34
  }
35

    
36
    /**
37
     * {@inheritdoc}
38
     */
39
  public function render($values) {
40
    $data = $values->{$this->field_alias};
41
    if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') {
42
      $fake_file = (object) array('filemime' => $data);
43
      $data = theme('file_icon', array('file' => $fake_file));
44
    }
45

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

    
49
}