Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / field / views_handler_argument_field_list.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * Argument handler for list field to show the human readable name in the
10
 * summary.
11
 *
12
 * @ingroup views_argument_handlers
13
 */
14
class views_handler_argument_field_list extends views_handler_argument_numeric {
15

    
16
  /**
17
   * Stores the allowed values of this field.
18
   *
19
   * @var array
20
   */
21
  public $allowed_values = NULL;
22

    
23
  /**
24
   * {@inheritdoc}
25
   */
26
  public function init(&$view, &$options) {
27
    parent::init($view, $options);
28
    $field = field_info_field($this->definition['field_name']);
29
    $this->allowed_values = list_allowed_values($field);
30
  }
31

    
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function option_definition() {
36
    $options = parent::option_definition();
37
    $options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
38

    
39
    return $options;
40
  }
41

    
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function options_form(&$form, &$form_state) {
46
    parent::options_form($form, $form_state);
47

    
48
    $form['summary']['human'] = array(
49
      '#title' => t('Display list value as human readable'),
50
      '#type' => 'checkbox',
51
      '#default_value' => $this->options['summary']['human'],
52
      '#dependency' => array('radio:options[default_action]' => array('summary')),
53
    );
54
  }
55

    
56
  /**
57
   * {@inheritdoc}
58
   */
59
  public function summary_name($data) {
60
    $value = $data->{$this->name_alias};
61
    // If the list element has a human readable name show it,
62
    if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
63
      return field_filter_xss($this->allowed_values[$value]);
64
    }
65
    // Else fallback to the key.
66
    else {
67
      return check_plain($value);
68
    }
69
  }
70

    
71
}