1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_machine_name.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler whichs allows to show machine name content as human name.
|
10
|
* @ingroup views_field_handlers
|
11
|
*
|
12
|
* Definition items:
|
13
|
* - options callback: The function to call in order to generate the value
|
14
|
* options. If omitted, the options 'Yes' and 'No' will be used.
|
15
|
* - options arguments: An array of arguments to pass to the options callback.
|
16
|
*/
|
17
|
class views_handler_field_machine_name extends views_handler_field {
|
18
|
|
19
|
/**
|
20
|
* @var array Stores the available options.
|
21
|
*/
|
22
|
public $value_options;
|
23
|
|
24
|
/**
|
25
|
* {@inheritdoc}
|
26
|
*/
|
27
|
public function get_value_options() {
|
28
|
if (isset($this->value_options)) {
|
29
|
return;
|
30
|
}
|
31
|
|
32
|
if (isset($this->definition['options callback']) && is_callable($this->definition['options callback'])) {
|
33
|
if (isset($this->definition['options arguments']) && is_array($this->definition['options arguments'])) {
|
34
|
$this->value_options = call_user_func_array($this->definition['options callback'], $this->definition['options arguments']);
|
35
|
}
|
36
|
else {
|
37
|
$this->value_options = call_user_func($this->definition['options callback']);
|
38
|
}
|
39
|
}
|
40
|
else {
|
41
|
$this->value_options = array();
|
42
|
}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* {@inheritdoc}
|
47
|
*/
|
48
|
public function option_definition() {
|
49
|
$options = parent::option_definition();
|
50
|
$options['machine_name'] = array('default' => FALSE, 'bool' => TRUE);
|
51
|
|
52
|
return $options;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* {@inheritdoc}
|
57
|
*/
|
58
|
public function options_form(&$form, &$form_state) {
|
59
|
parent::options_form($form, $form_state);
|
60
|
|
61
|
$form['machine_name'] = array(
|
62
|
'#title' => t('Output machine name'),
|
63
|
'#description' => t('Display field as machine name.'),
|
64
|
'#type' => 'checkbox',
|
65
|
'#default_value' => !empty($this->options['machine_name']),
|
66
|
);
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* {@inheritdoc}
|
71
|
*/
|
72
|
public function pre_render(&$values) {
|
73
|
$this->get_value_options();
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* {@inheritdoc}
|
78
|
*/
|
79
|
public function render($values) {
|
80
|
$value = $values->{$this->field_alias};
|
81
|
if (!empty($this->options['machine_name']) || !isset($this->value_options[$value])) {
|
82
|
$result = check_plain($value);
|
83
|
}
|
84
|
else {
|
85
|
$result = $this->value_options[$value];
|
86
|
}
|
87
|
|
88
|
return $result;
|
89
|
}
|
90
|
|
91
|
}
|