1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of views_handler_field_serialized.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Field handler to show data of serialized fields.
|
10 |
|
|
*
|
11 |
|
|
* @ingroup views_field_handlers
|
12 |
|
|
*/
|
13 |
|
|
class views_handler_field_serialized extends views_handler_field {
|
14 |
|
|
|
15 |
|
|
function option_definition() {
|
16 |
|
|
$options = parent::option_definition();
|
17 |
|
|
$options['format'] = array('default' => 'unserialized');
|
18 |
|
|
$options['key'] = array('default' => '');
|
19 |
|
|
return $options;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
function options_form(&$form, &$form_state) {
|
24 |
|
|
parent::options_form($form, $form_state);
|
25 |
|
|
|
26 |
|
|
$form['format'] = array(
|
27 |
|
|
'#type' => 'select',
|
28 |
|
|
'#title' => t('Display format'),
|
29 |
|
|
'#description' => t('How should the serialized data be displayed. You can choose a custom array/object key or a print_r on the full output.'),
|
30 |
|
|
'#options' => array(
|
31 |
|
|
'unserialized' => t('Full data (unserialized)'),
|
32 |
|
|
'serialized' => t('Full data (serialized)'),
|
33 |
|
|
'key' => t('A certain key'),
|
34 |
|
|
),
|
35 |
|
|
'#default_value' => $this->options['format'],
|
36 |
|
|
);
|
37 |
|
|
$form['key'] = array(
|
38 |
|
|
'#type' => 'textfield',
|
39 |
|
|
'#title' => t('Which key should be displayed'),
|
40 |
|
|
'#default_value' => $this->options['key'],
|
41 |
|
|
'#dependency' => array('edit-options-format' => array('key')),
|
42 |
|
|
);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
function options_validate(&$form, &$form_state) {
|
46 |
|
|
// Require a key if the format is key.
|
47 |
|
|
if ($form_state['values']['options']['format'] == 'key' && $form_state['values']['options']['key'] == '') {
|
48 |
|
|
form_error($form['key'], t('You have to enter a key if you want to display a key of the data.'));
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
function render($values) {
|
53 |
|
|
$value = $values->{$this->field_alias};
|
54 |
|
|
|
55 |
|
|
if ($this->options['format'] == 'unserialized') {
|
56 |
|
|
return check_plain(print_r(unserialize($value), TRUE));
|
57 |
|
|
}
|
58 |
|
|
elseif ($this->options['format'] == 'key' && !empty($this->options['key'])) {
|
59 |
|
|
$value = (array) unserialize($value);
|
60 |
|
|
return check_plain($value[$this->options['key']]);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
return $value;
|
64 |
|
|
}
|
65 |
|
|
} |