commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / field / views_handler_argument_field_list.inc
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 * Stores the allowed values of this field.
17 *
18 * @var array
19 */
20 var $allowed_values = NULL;
21
22 function init(&$view, &$options) {
23 parent::init($view, $options);
24 $field = field_info_field($this->definition['field_name']);
25 $this->allowed_values = list_allowed_values($field);
26 }
27
28 function option_definition() {
29 $options = parent::option_definition();
30 $options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
31
32 return $options;
33 }
34
35 function options_form(&$form, &$form_state) {
36 parent::options_form($form, $form_state);
37
38 $form['summary']['human'] = array(
39 '#title' => t('Display list value as human readable'),
40 '#type' => 'checkbox',
41 '#default_value' => $this->options['summary']['human'],
42 '#dependency' => array('radio:options[default_action]' => array('summary')),
43 );
44 }
45
46
47 function summary_name($data) {
48 $value = $data->{$this->name_alias};
49 // If the list element has a human readable name show it,
50 if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
51 return field_filter_xss($this->allowed_values[$value]);
52 }
53 // else fallback to the key.
54 else {
55 return check_plain($value);
56 }
57 }
58 }