Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / node / views_handler_field_node_type.inc @ 13755f8d

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
  function option_definition() {
15
    $options = parent::option_definition();
16
    $options['machine_name'] = array('default' => FALSE, 'bool' => TRUE);
17

    
18
    return $options;
19
  }
20

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

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

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

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