Projet

Général

Profil

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

root / drupal7 / sites / all / modules / file_entity / views / views_handler_field_file_type.inc @ 66c11afc

1
<?php
2

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

    
8
/**
9
 * Field handler to translate a file type into its readable form.
10
 */
11
class views_handler_field_file_type extends views_handler_field_file {
12
  function option_definition() {
13
    $options = parent::option_definition();
14
    $options['machine_name'] = array('default' => FALSE);
15

    
16
    return $options;
17
  }
18

    
19
  /**
20
   * Provide machine_name option for to file type display.
21
   */
22
  function options_form(&$form, &$form_state) {
23
    parent::options_form($form, $form_state);
24

    
25
    $form['machine_name'] = array(
26
      '#title' => t('Output machine name'),
27
      '#description' => t('Display field as the file type machine name.'),
28
      '#type' => 'checkbox',
29
      '#default_value' => !empty($this->options['machine_name']),
30
      '#fieldset' => 'more',
31
    );
32
  }
33

    
34
  /**
35
    * Render file type as human readable name, unless using machine_name option.
36
    */
37
  function render_name($data, $values) {
38
    if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
39
      return t($this->sanitize_value(file_entity_type_get_name($data)));
40
    }
41
    return $this->sanitize_value($data);
42
  }
43

    
44
  function render($values) {
45
    $value = $this->get_value($values);
46
    return $this->render_link($this->render_name($value, $values), $values);
47
  }
48
}