Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_argument_field_list_string.
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_string extends views_handler_argument_string {
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

    
38
    $options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
39

    
40
    return $options;
41
  }
42

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

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

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

    
72
}