1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of views_handler_field_prerender_list.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Field handler to provide a list of items.
|
10 |
|
|
*
|
11 |
|
|
* The items are expected to be loaded by a child object during pre_render,
|
12 |
|
|
* and 'my field' is expected to be the pointer to the items in the list.
|
13 |
|
|
*
|
14 |
|
|
* Items to render should be in a list in $this->items
|
15 |
|
|
*
|
16 |
|
|
* @ingroup views_field_handlers
|
17 |
|
|
*/
|
18 |
|
|
class views_handler_field_prerender_list extends views_handler_field {
|
19 |
|
|
/**
|
20 |
|
|
* Stores all items which are used to render the items.
|
21 |
|
|
* It should be keyed first by the id of the base table, for example nid.
|
22 |
|
|
* The second key is the id of the thing which is displayed multiple times
|
23 |
|
|
* per row, for example the tid.
|
24 |
|
|
*
|
25 |
|
|
* @var array
|
26 |
|
|
*/
|
27 |
|
|
var $items = array();
|
28 |
|
|
|
29 |
|
|
function option_definition() {
|
30 |
|
|
$options = parent::option_definition();
|
31 |
|
|
|
32 |
|
|
$options['type'] = array('default' => 'separator');
|
33 |
|
|
$options['separator'] = array('default' => ', ');
|
34 |
|
|
|
35 |
|
|
return $options;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
function options_form(&$form, &$form_state) {
|
39 |
|
|
$form['type'] = array(
|
40 |
|
|
'#type' => 'radios',
|
41 |
|
|
'#title' => t('Display type'),
|
42 |
|
|
'#options' => array(
|
43 |
|
|
'ul' => t('Unordered list'),
|
44 |
|
|
'ol' => t('Ordered list'),
|
45 |
|
|
'separator' => t('Simple separator'),
|
46 |
|
|
),
|
47 |
|
|
'#default_value' => $this->options['type'],
|
48 |
|
|
);
|
49 |
|
|
|
50 |
|
|
$form['separator'] = array(
|
51 |
|
|
'#type' => 'textfield',
|
52 |
|
|
'#title' => t('Separator'),
|
53 |
|
|
'#default_value' => $this->options['separator'],
|
54 |
|
|
'#dependency' => array('radio:options[type]' => array('separator')),
|
55 |
|
|
);
|
56 |
|
|
parent::options_form($form, $form_state);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Render the field.
|
61 |
|
|
*
|
62 |
|
|
* This function is deprecated, but left in for older systems that have not
|
63 |
|
|
* yet or won't update their prerender list fields. If a render_item method
|
64 |
|
|
* exists, this will not get used by advanced_render.
|
65 |
|
|
*/
|
66 |
|
|
function render($values) {
|
67 |
|
|
$field = $this->get_value($values);
|
68 |
|
|
if (!empty($this->items[$field])) {
|
69 |
|
|
if ($this->options['type'] == 'separator') {
|
70 |
|
|
return implode($this->sanitize_value($this->options['separator']), $this->items[$field]);
|
71 |
|
|
}
|
72 |
|
|
else {
|
73 |
|
|
return theme('item_list',
|
74 |
|
|
array(
|
75 |
|
|
'items' => $this->items[$field],
|
76 |
|
|
'title' => NULL,
|
77 |
|
|
'type' => $this->options['type']
|
78 |
|
|
));
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/**
|
84 |
|
|
* Render all items in this field together.
|
85 |
|
|
*
|
86 |
|
|
* When using advanced render, each possible item in the list is rendered
|
87 |
|
|
* individually. Then the items are all pasted together.
|
88 |
|
|
*/
|
89 |
|
|
function render_items($items) {
|
90 |
|
|
if (!empty($items)) {
|
91 |
|
|
if ($this->options['type'] == 'separator') {
|
92 |
|
|
return implode($this->sanitize_value($this->options['separator'], 'xss_admin'), $items);
|
93 |
|
|
}
|
94 |
|
|
else {
|
95 |
|
|
return theme('item_list',
|
96 |
|
|
array(
|
97 |
|
|
'items' => $items,
|
98 |
|
|
'title' => NULL,
|
99 |
|
|
'type' => $this->options['type']
|
100 |
|
|
));
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
/**
|
106 |
|
|
* Return an array of items for the field.
|
107 |
|
|
*
|
108 |
|
|
* Items should be stored in the result array, if possible, as an array
|
109 |
|
|
* with 'value' as the actual displayable value of the item, plus
|
110 |
|
|
* any items that might be found in the 'alter' options array for
|
111 |
|
|
* creating links, such as 'path', 'fragment', 'query' etc, such a thing
|
112 |
|
|
* is to be made. Additionally, items that might be turned into tokens
|
113 |
|
|
* should also be in this array.
|
114 |
|
|
*/
|
115 |
|
|
function get_items($values) {
|
116 |
|
|
// Only the parent get_value returns a single field.
|
117 |
|
|
$field = parent::get_value($values);
|
118 |
|
|
if (!empty($this->items[$field])) {
|
119 |
|
|
return $this->items[$field];
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
return array();
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/**
|
126 |
|
|
* Get the value that's supposed to be rendered.
|
127 |
|
|
*
|
128 |
|
|
* @param $values
|
129 |
|
|
* An object containing all retrieved values.
|
130 |
|
|
* @param $field
|
131 |
|
|
* Optional name of the field where the value is stored.
|
132 |
|
|
* @param $raw
|
133 |
|
|
* Use the raw data and not the data defined in pre_render
|
134 |
|
|
*/
|
135 |
|
|
function get_value($values, $field = NULL, $raw = FALSE) {
|
136 |
|
|
if ($raw) {
|
137 |
|
|
return parent::get_value($values, $field);
|
138 |
|
|
}
|
139 |
|
|
$item = $this->get_items($values);
|
140 |
|
|
$item = (array) $item;
|
141 |
|
|
if (isset($field) && isset($item[$field])) {
|
142 |
|
|
return $item[$field];
|
143 |
|
|
}
|
144 |
|
|
return $item;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/**
|
148 |
|
|
* Determine if advanced rendering is allowed.
|
149 |
|
|
*
|
150 |
|
|
* By default, advanced rendering will NOT be allowed if the class
|
151 |
|
|
* inheriting from this does not implement a 'render_items' method.
|
152 |
|
|
*/
|
153 |
|
|
function allow_advanced_render() {
|
154 |
|
|
// Note that the advanced render bits also use the presence of
|
155 |
|
|
// this method to determine if it needs to render items as a list.
|
156 |
|
|
return method_exists($this, 'render_item');
|
157 |
|
|
}
|
158 |
|
|
} |