Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / node / views_handler_field_node_type.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * Field handler to translate a node type into its readable form.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_node_type extends views_handler_field_node {
14

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

    
22
    return $options;
23
  }
24

    
25
  /**
26
   * Provide machine_name option for to node type display.
27
   */
28
  public function options_form(&$form, &$form_state) {
29
    parent::options_form($form, $form_state);
30

    
31
    $form['machine_name'] = array(
32
      '#title' => t('Output machine name'),
33
      '#description' => t('Display field as the content type machine name.'),
34
      '#type' => 'checkbox',
35
      '#default_value' => !empty($this->options['machine_name']),
36
    );
37
  }
38

    
39
  /**
40
   * Render node type as human readable name, unless using machine_name option.
41
   */
42
  public function render_name($data, $values) {
43
    if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
44
      return t($this->sanitize_value(node_type_get_name($data)));
45
    }
46
    return $this->sanitize_value($data);
47
  }
48

    
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function render($values) {
53
    $value = $this->get_value($values);
54
    return $this->render_link($this->render_name($value, $values), $values);
55
  }
56

    
57
}