danielebarchiesi@0
|
1 <?php
|
danielebarchiesi@0
|
2
|
danielebarchiesi@0
|
3 /**
|
danielebarchiesi@0
|
4 * @file
|
danielebarchiesi@0
|
5 * @todo.
|
danielebarchiesi@0
|
6 */
|
danielebarchiesi@0
|
7
|
danielebarchiesi@0
|
8 /**
|
danielebarchiesi@0
|
9 * @defgroup views_argument_handlers Views argument handlers
|
danielebarchiesi@0
|
10 * Handlers to tell Views how to contextually filter queries.
|
danielebarchiesi@0
|
11 * @{
|
danielebarchiesi@0
|
12 */
|
danielebarchiesi@0
|
13
|
danielebarchiesi@0
|
14 /**
|
danielebarchiesi@0
|
15 * Base class for arguments.
|
danielebarchiesi@0
|
16 *
|
danielebarchiesi@0
|
17 * The basic argument works for very simple arguments such as nid and uid
|
danielebarchiesi@0
|
18 *
|
danielebarchiesi@0
|
19 * Definition terms for this handler:
|
danielebarchiesi@0
|
20 * - name field: The field to use for the name to use in the summary, which is
|
danielebarchiesi@0
|
21 * the displayed output. For example, for the node: nid argument,
|
danielebarchiesi@0
|
22 * the argument itself is the nid, but node.title is displayed.
|
danielebarchiesi@0
|
23 * - name table: The table to use for the name, should it not be in the same
|
danielebarchiesi@0
|
24 * table as the argument.
|
danielebarchiesi@0
|
25 * - empty field name: For arguments that can have no value, such as taxonomy
|
danielebarchiesi@0
|
26 * which can have "no term", this is the string which
|
danielebarchiesi@0
|
27 * will be displayed for this lack of value. Be sure to use
|
danielebarchiesi@0
|
28 * t().
|
danielebarchiesi@0
|
29 * - validate type: A little used string to allow an argument to restrict
|
danielebarchiesi@0
|
30 * which validator is available to just one. Use the
|
danielebarchiesi@0
|
31 * validator ID. This probably should not be used at all,
|
danielebarchiesi@0
|
32 * and may disappear or change.
|
danielebarchiesi@0
|
33 * - numeric: If set to TRUE this field is numeric and will use %d instead of
|
danielebarchiesi@0
|
34 * %s in queries.
|
danielebarchiesi@0
|
35 *
|
danielebarchiesi@0
|
36 * @ingroup views_argument_handlers
|
danielebarchiesi@0
|
37 */
|
danielebarchiesi@0
|
38 class views_handler_argument extends views_handler {
|
danielebarchiesi@0
|
39 var $validator = NULL;
|
danielebarchiesi@0
|
40 var $argument = NULL;
|
danielebarchiesi@0
|
41 var $value = NULL;
|
danielebarchiesi@0
|
42
|
danielebarchiesi@0
|
43 /**
|
danielebarchiesi@0
|
44 * The table to use for the name, should it not be in the same table as the argument.
|
danielebarchiesi@0
|
45 * @var string
|
danielebarchiesi@0
|
46 */
|
danielebarchiesi@0
|
47 var $name_table;
|
danielebarchiesi@0
|
48
|
danielebarchiesi@0
|
49 /**
|
danielebarchiesi@0
|
50 * The field to use for the name to use in the summary, which is
|
danielebarchiesi@0
|
51 * the displayed output. For example, for the node: nid argument,
|
danielebarchiesi@0
|
52 * the argument itself is the nid, but node.title is displayed.
|
danielebarchiesi@0
|
53 * @var string
|
danielebarchiesi@0
|
54 */
|
danielebarchiesi@0
|
55 var $name_field;
|
danielebarchiesi@0
|
56
|
danielebarchiesi@0
|
57 /**
|
danielebarchiesi@0
|
58 * Constructor
|
danielebarchiesi@0
|
59 */
|
danielebarchiesi@0
|
60 function construct() {
|
danielebarchiesi@0
|
61 parent::construct();
|
danielebarchiesi@0
|
62
|
danielebarchiesi@0
|
63 if (!empty($this->definition['name field'])) {
|
danielebarchiesi@0
|
64 $this->name_field = $this->definition['name field'];
|
danielebarchiesi@0
|
65 }
|
danielebarchiesi@0
|
66 if (!empty($this->definition['name table'])) {
|
danielebarchiesi@0
|
67 $this->name_table = $this->definition['name table'];
|
danielebarchiesi@0
|
68 }
|
danielebarchiesi@0
|
69 }
|
danielebarchiesi@0
|
70
|
danielebarchiesi@0
|
71 function init(&$view, &$options) {
|
danielebarchiesi@0
|
72 parent::init($view, $options);
|
danielebarchiesi@0
|
73
|
danielebarchiesi@0
|
74 // Compatibility: The new UI changed several settings.
|
danielebarchiesi@0
|
75 if (!empty($options['wildcard']) && !isset($options['exception']['value'])) {
|
danielebarchiesi@0
|
76 $this->options['exception']['value'] = $options['wildcard'];
|
danielebarchiesi@0
|
77 }
|
danielebarchiesi@0
|
78 if (!empty($options['wildcard_substitution']) && !isset($options['exception']['title'])) {
|
danielebarchiesi@0
|
79 // Enable the checkbox if the title is filled in.
|
danielebarchiesi@0
|
80 $this->options['exception']['title_enable'] = 1;
|
danielebarchiesi@0
|
81 $this->options['exception']['title'] = $options['wildcard_substitution'];
|
danielebarchiesi@0
|
82 }
|
danielebarchiesi@0
|
83
|
danielebarchiesi@0
|
84 if (!isset($options['summary']['format']) && !empty($options['style_plugin'])) {
|
danielebarchiesi@0
|
85 $this->options['summary']['format'] = $options['style_plugin'];
|
danielebarchiesi@0
|
86 }
|
danielebarchiesi@0
|
87
|
danielebarchiesi@0
|
88 // Setup default value.
|
danielebarchiesi@0
|
89 $options['style_options'] = isset($options['style_options']) ? $options['style_options'] : array();
|
danielebarchiesi@0
|
90
|
danielebarchiesi@0
|
91 if (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc') {
|
danielebarchiesi@0
|
92 $this->options['default_action'] = 'summary';
|
danielebarchiesi@0
|
93 $this->options['summary']['sort_order'] = 'asc';
|
danielebarchiesi@0
|
94 $this->options['summary']['number_of_records'] = 0;
|
danielebarchiesi@0
|
95 $this->options['summary_options'] = $options['style_options'];
|
danielebarchiesi@0
|
96 }
|
danielebarchiesi@0
|
97 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc') {
|
danielebarchiesi@0
|
98 $this->options['default_action'] = 'summary';
|
danielebarchiesi@0
|
99 $this->options['summary']['sort_order'] = 'desc';
|
danielebarchiesi@0
|
100 $this->options['summary']['number_of_records'] = 0;
|
danielebarchiesi@0
|
101 $this->options['summary_options'] = $options['style_options'];
|
danielebarchiesi@0
|
102 }
|
danielebarchiesi@0
|
103 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc by count') {
|
danielebarchiesi@0
|
104 $this->options['default_action'] = 'summary';
|
danielebarchiesi@0
|
105 $this->options['summary']['sort_order'] = 'asc';
|
danielebarchiesi@0
|
106 $this->options['summary']['number_of_records'] = 1;
|
danielebarchiesi@0
|
107 $this->options['summary_options'] = $options['style_options'];
|
danielebarchiesi@0
|
108 }
|
danielebarchiesi@0
|
109 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc by count') {
|
danielebarchiesi@0
|
110 $this->options['default_action'] = 'summary';
|
danielebarchiesi@0
|
111 $this->options['summary']['sort_order'] = 'desc';
|
danielebarchiesi@0
|
112 $this->options['summary']['number_of_records'] = 1;
|
danielebarchiesi@0
|
113 $this->options['summary_options'] = $options['style_options'];
|
danielebarchiesi@0
|
114 }
|
danielebarchiesi@0
|
115
|
danielebarchiesi@0
|
116 if (!empty($options['title']) && !isset($options['title_enable'])) {
|
danielebarchiesi@0
|
117 $this->options['title_enable'] = 1;
|
danielebarchiesi@0
|
118 }
|
danielebarchiesi@0
|
119 if (!empty($options['breadcrumb']) && !isset($options['breadcrumb_enable'])) {
|
danielebarchiesi@0
|
120 $this->options['breadcrumb_enable'] = 1;
|
danielebarchiesi@0
|
121 }
|
danielebarchiesi@0
|
122
|
danielebarchiesi@0
|
123 if (!empty($options['validate_type']) && !isset($options['validate']['type'])) {
|
danielebarchiesi@0
|
124 $this->options['validate']['type'] = $options['validate_type'];
|
danielebarchiesi@0
|
125 $this->options['specify_validation'] = 1;
|
danielebarchiesi@0
|
126 }
|
danielebarchiesi@0
|
127 if (!empty($options['validate_fail']) && !isset($options['validate']['fail'])) {
|
danielebarchiesi@0
|
128 $this->options['validate']['fail'] = $options['validate_fail'];
|
danielebarchiesi@0
|
129 $this->options['specify_validation'] = 1;
|
danielebarchiesi@0
|
130 }
|
danielebarchiesi@0
|
131 }
|
danielebarchiesi@0
|
132
|
danielebarchiesi@0
|
133 /**
|
danielebarchiesi@0
|
134 * Give an argument the opportunity to modify the breadcrumb, if it wants.
|
danielebarchiesi@0
|
135 * This only gets called on displays where a breadcrumb is actually used.
|
danielebarchiesi@0
|
136 *
|
danielebarchiesi@0
|
137 * The breadcrumb will be in the form of an array, with the keys being
|
danielebarchiesi@0
|
138 * the path and the value being the already sanitized title of the path.
|
danielebarchiesi@0
|
139 */
|
danielebarchiesi@0
|
140 function set_breadcrumb(&$breadcrumb) { }
|
danielebarchiesi@0
|
141
|
danielebarchiesi@0
|
142 /**
|
danielebarchiesi@0
|
143 * Determine if the argument can generate a breadcrumb
|
danielebarchiesi@0
|
144 *
|
danielebarchiesi@0
|
145 * @return TRUE/FALSE
|
danielebarchiesi@0
|
146 */
|
danielebarchiesi@0
|
147 function uses_breadcrumb() {
|
danielebarchiesi@0
|
148 $info = $this->default_actions($this->options['default_action']);
|
danielebarchiesi@0
|
149 return !empty($info['breadcrumb']);
|
danielebarchiesi@0
|
150 }
|
danielebarchiesi@0
|
151
|
danielebarchiesi@0
|
152 function is_exception($arg = NULL) {
|
danielebarchiesi@0
|
153 if (!isset($arg)) {
|
danielebarchiesi@0
|
154 $arg = isset($this->argument) ? $this->argument : NULL;
|
danielebarchiesi@0
|
155 }
|
danielebarchiesi@0
|
156 return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg;
|
danielebarchiesi@0
|
157 }
|
danielebarchiesi@0
|
158
|
danielebarchiesi@0
|
159 function exception_title() {
|
danielebarchiesi@0
|
160 // If title overriding is off for the exception, return the normal title.
|
danielebarchiesi@0
|
161 if (empty($this->options['exception']['title_enable'])) {
|
danielebarchiesi@0
|
162 return $this->get_title();
|
danielebarchiesi@0
|
163 }
|
danielebarchiesi@0
|
164 return $this->options['exception']['title'];
|
danielebarchiesi@0
|
165 }
|
danielebarchiesi@0
|
166
|
danielebarchiesi@0
|
167 /**
|
danielebarchiesi@0
|
168 * Determine if the argument needs a style plugin.
|
danielebarchiesi@0
|
169 *
|
danielebarchiesi@0
|
170 * @return TRUE/FALSE
|
danielebarchiesi@0
|
171 */
|
danielebarchiesi@0
|
172 function needs_style_plugin() {
|
danielebarchiesi@0
|
173 $info = $this->default_actions($this->options['default_action']);
|
danielebarchiesi@0
|
174 $validate_info = $this->default_actions($this->options['validate']['fail']);
|
danielebarchiesi@0
|
175 return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
|
danielebarchiesi@0
|
176 }
|
danielebarchiesi@0
|
177
|
danielebarchiesi@0
|
178 function option_definition() {
|
danielebarchiesi@0
|
179 $options = parent::option_definition();
|
danielebarchiesi@0
|
180
|
danielebarchiesi@0
|
181 $options['default_action'] = array('default' => 'ignore');
|
danielebarchiesi@0
|
182 $options['exception'] = array(
|
danielebarchiesi@0
|
183 'contains' => array(
|
danielebarchiesi@0
|
184 'value' => array('default' => 'all'),
|
danielebarchiesi@0
|
185 'title_enable' => array('default' => FALSE, 'bool' => TRUE),
|
danielebarchiesi@0
|
186 'title' => array('default' => 'All', 'translatable' => TRUE),
|
danielebarchiesi@0
|
187 ),
|
danielebarchiesi@0
|
188 );
|
danielebarchiesi@0
|
189 $options['title_enable'] = array('default' => FALSE, 'bool' => TRUE);
|
danielebarchiesi@0
|
190 $options['title'] = array('default' => '', 'translatable' => TRUE);
|
danielebarchiesi@0
|
191 $options['breadcrumb_enable'] = array('default' => FALSE, 'bool' => TRUE);
|
danielebarchiesi@0
|
192 $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE);
|
danielebarchiesi@0
|
193 $options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
|
danielebarchiesi@0
|
194 $options['default_argument_options'] = array('default' => array(), 'export' => FALSE);
|
danielebarchiesi@0
|
195 $options['default_argument_skip_url'] = array('default' => FALSE, 'bool' => TRUE);
|
danielebarchiesi@0
|
196 $options['summary_options'] = array('default' => array(), 'export' => FALSE);
|
danielebarchiesi@0
|
197 $options['summary'] = array(
|
danielebarchiesi@0
|
198 'contains' => array(
|
danielebarchiesi@0
|
199 'sort_order' => array('default' => 'asc'),
|
danielebarchiesi@0
|
200 'number_of_records' => array('default' => 0),
|
danielebarchiesi@0
|
201 'format' => array('default' => 'default_summary', 'export' => 'export_summary'),
|
danielebarchiesi@0
|
202 ),
|
danielebarchiesi@0
|
203 );
|
danielebarchiesi@0
|
204 $options['specify_validation'] = array('default' => FALSE, 'bool' => TRUE);
|
danielebarchiesi@0
|
205 $options['validate'] = array(
|
danielebarchiesi@0
|
206 'contains' => array(
|
danielebarchiesi@0
|
207 'type' => array('default' => 'none', 'export' => 'export_validation'),
|
danielebarchiesi@0
|
208 'fail' => array('default' => 'not found'),
|
danielebarchiesi@0
|
209 ),
|
danielebarchiesi@0
|
210 );
|
danielebarchiesi@0
|
211 $options['validate_options'] = array('default' => array(), 'export' => FALSE);
|
danielebarchiesi@0
|
212
|
danielebarchiesi@0
|
213 return $options;
|
danielebarchiesi@0
|
214 }
|
danielebarchiesi@0
|
215
|
danielebarchiesi@0
|
216 function options_form(&$form, &$form_state) {
|
danielebarchiesi@0
|
217 parent::options_form($form, $form_state);
|
danielebarchiesi@0
|
218
|
danielebarchiesi@0
|
219 $argument_text = $this->view->display_handler->get_argument_text();
|
danielebarchiesi@0
|
220
|
danielebarchiesi@0
|
221 $form['#pre_render'][] = 'views_ui_pre_render_move_argument_options';
|
danielebarchiesi@0
|
222
|
danielebarchiesi@0
|
223 $form['description'] = array(
|
danielebarchiesi@0
|
224 '#markup' => $argument_text['description'],
|
danielebarchiesi@0
|
225 '#theme_wrappers' => array('container'),
|
danielebarchiesi@0
|
226 '#attributes' => array('class' => array('description')),
|
danielebarchiesi@0
|
227 );
|
danielebarchiesi@0
|
228
|
danielebarchiesi@0
|
229 $form['no_argument'] = array(
|
danielebarchiesi@0
|
230 '#type' => 'fieldset',
|
danielebarchiesi@0
|
231 '#title' => $argument_text['filter value not present'],
|
danielebarchiesi@0
|
232 );
|
danielebarchiesi@0
|
233 // Everything in the fieldset is floated, so the last element needs to
|
danielebarchiesi@0
|
234 // clear those floats.
|
danielebarchiesi@0
|
235 $form['no_argument']['clearfix'] = array(
|
danielebarchiesi@0
|
236 '#weight' => 1000,
|
danielebarchiesi@0
|
237 '#markup' => '<div class="clearfix"></div>',
|
danielebarchiesi@0
|
238 );
|
danielebarchiesi@0
|
239 $form['default_action'] = array(
|
danielebarchiesi@0
|
240 '#type' => 'radios',
|
danielebarchiesi@0
|
241 '#process' => array('views_ui_process_container_radios'),
|
danielebarchiesi@0
|
242 '#default_value' => $this->options['default_action'],
|
danielebarchiesi@0
|
243 '#fieldset' => 'no_argument',
|
danielebarchiesi@0
|
244 );
|
danielebarchiesi@0
|
245
|
danielebarchiesi@0
|
246 $form['exception'] = array(
|
danielebarchiesi@0
|
247 '#type' => 'fieldset',
|
danielebarchiesi@0
|
248 '#title' => t('Exceptions'),
|
danielebarchiesi@0
|
249 '#collapsible' => TRUE,
|
danielebarchiesi@0
|
250 '#collapsed' => TRUE,
|
danielebarchiesi@0
|
251 '#fieldset' => 'no_argument',
|
danielebarchiesi@0
|
252 );
|
danielebarchiesi@0
|
253 $form['exception']['value'] = array(
|
danielebarchiesi@0
|
254 '#type' => 'textfield',
|
danielebarchiesi@0
|
255 '#title' => t('Exception value'),
|
danielebarchiesi@0
|
256 '#size' => 20,
|
danielebarchiesi@0
|
257 '#default_value' => $this->options['exception']['value'],
|
danielebarchiesi@0
|
258 '#description' => t('If this value is received, the filter will be ignored; i.e, "all values"'),
|
danielebarchiesi@0
|
259 );
|
danielebarchiesi@0
|
260 $form['exception']['title_enable'] = array(
|
danielebarchiesi@0
|
261 '#type' => 'checkbox',
|
danielebarchiesi@0
|
262 '#title' => t('Override title'),
|
danielebarchiesi@0
|
263 '#default_value' => $this->options['exception']['title_enable'],
|
danielebarchiesi@0
|
264 );
|
danielebarchiesi@0
|
265 $form['exception']['title'] = array(
|
danielebarchiesi@0
|
266 '#type' => 'textfield',
|
danielebarchiesi@0
|
267 '#title' => t('Override title'),
|
danielebarchiesi@0
|
268 '#title_display' => 'invisible',
|
danielebarchiesi@0
|
269 '#size' => 20,
|
danielebarchiesi@0
|
270 '#default_value' => $this->options['exception']['title'],
|
danielebarchiesi@0
|
271 '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
|
danielebarchiesi@0
|
272 '#dependency' => array(
|
danielebarchiesi@0
|
273 'edit-options-exception-title-enable' => array('1'),
|
danielebarchiesi@0
|
274 ),
|
danielebarchiesi@0
|
275 );
|
danielebarchiesi@0
|
276
|
danielebarchiesi@0
|
277 $options = array();
|
danielebarchiesi@0
|
278 $defaults = $this->default_actions();
|
danielebarchiesi@0
|
279 $validate_options = array();
|
danielebarchiesi@0
|
280 foreach ($defaults as $id => $info) {
|
danielebarchiesi@0
|
281 $options[$id] = $info['title'];
|
danielebarchiesi@0
|
282 if (empty($info['default only'])) {
|
danielebarchiesi@0
|
283 $validate_options[$id] = $info['title'];
|
danielebarchiesi@0
|
284 }
|
danielebarchiesi@0
|
285 if (!empty($info['form method'])) {
|
danielebarchiesi@0
|
286 $this->{$info['form method']}($form, $form_state);
|
danielebarchiesi@0
|
287 }
|
danielebarchiesi@0
|
288 }
|
danielebarchiesi@0
|
289 $form['default_action']['#options'] = $options;
|
danielebarchiesi@0
|
290
|
danielebarchiesi@0
|
291 $form['argument_present'] = array(
|
danielebarchiesi@0
|
292 '#type' => 'fieldset',
|
danielebarchiesi@0
|
293 '#title' => $argument_text['filter value present'],
|
danielebarchiesi@0
|
294 );
|
danielebarchiesi@0
|
295 $form['title_enable'] = array(
|
danielebarchiesi@0
|
296 '#type' => 'checkbox',
|
danielebarchiesi@0
|
297 '#title' => t('Override title'),
|
danielebarchiesi@0
|
298 '#default_value' => $this->options['title_enable'],
|
danielebarchiesi@0
|
299 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
300 );
|
danielebarchiesi@0
|
301 $form['title'] = array(
|
danielebarchiesi@0
|
302 '#type' => 'textfield',
|
danielebarchiesi@0
|
303 '#title' => t('Provide title'),
|
danielebarchiesi@0
|
304 '#title_display' => 'invisible',
|
danielebarchiesi@0
|
305 '#default_value' => $this->options['title'],
|
danielebarchiesi@0
|
306 '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
|
danielebarchiesi@0
|
307 '#dependency' => array(
|
danielebarchiesi@0
|
308 'edit-options-title-enable' => array('1'),
|
danielebarchiesi@0
|
309 ),
|
danielebarchiesi@0
|
310 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
311 );
|
danielebarchiesi@0
|
312
|
danielebarchiesi@0
|
313 $form['breadcrumb_enable'] = array(
|
danielebarchiesi@0
|
314 '#type' => 'checkbox',
|
danielebarchiesi@0
|
315 '#title' => t('Override breadcrumb'),
|
danielebarchiesi@0
|
316 '#default_value' => $this->options['breadcrumb_enable'],
|
danielebarchiesi@0
|
317 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
318 );
|
danielebarchiesi@0
|
319 $form['breadcrumb'] = array(
|
danielebarchiesi@0
|
320 '#type' => 'textfield',
|
danielebarchiesi@0
|
321 '#title' => t('Provide breadcrumb'),
|
danielebarchiesi@0
|
322 '#title_display' => 'invisible',
|
danielebarchiesi@0
|
323 '#default_value' => $this->options['breadcrumb'],
|
danielebarchiesi@0
|
324 '#description' => t('Enter a breadcrumb name you would like to use. See "Title" for percent substitutions.'),
|
danielebarchiesi@0
|
325 '#dependency' => array(
|
danielebarchiesi@0
|
326 'edit-options-breadcrumb-enable' => array('1'),
|
danielebarchiesi@0
|
327 ),
|
danielebarchiesi@0
|
328 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
329 );
|
danielebarchiesi@0
|
330
|
danielebarchiesi@0
|
331 $form['specify_validation'] = array(
|
danielebarchiesi@0
|
332 '#type' => 'checkbox',
|
danielebarchiesi@0
|
333 '#title' => t('Specify validation criteria'),
|
danielebarchiesi@0
|
334 '#default_value' => $this->options['specify_validation'],
|
danielebarchiesi@0
|
335 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
336 );
|
danielebarchiesi@0
|
337
|
danielebarchiesi@0
|
338 $form['validate'] = array(
|
danielebarchiesi@0
|
339 '#type' => 'container',
|
danielebarchiesi@0
|
340 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
341 );
|
danielebarchiesi@0
|
342 // @todo The mockup wanted to use "Validate using" here, but it doesn't
|
danielebarchiesi@0
|
343 // work well with many options (they'd need to be changed as well)
|
danielebarchiesi@0
|
344 $form['validate']['type'] = array(
|
danielebarchiesi@0
|
345 '#type' => 'select',
|
danielebarchiesi@0
|
346 '#title' => t('Validator'),
|
danielebarchiesi@0
|
347 '#default_value' => $this->options['validate']['type'],
|
danielebarchiesi@0
|
348 '#dependency' => array(
|
danielebarchiesi@0
|
349 'edit-options-specify-validation' => array('1'),
|
danielebarchiesi@0
|
350 ),
|
danielebarchiesi@0
|
351 );
|
danielebarchiesi@0
|
352
|
danielebarchiesi@0
|
353 $validate_types = array('none' => t('- Basic validation -'));
|
danielebarchiesi@0
|
354 $plugins = views_fetch_plugin_data('argument validator');
|
danielebarchiesi@0
|
355 foreach ($plugins as $id => $info) {
|
danielebarchiesi@0
|
356 if (!empty($info['no ui'])) {
|
danielebarchiesi@0
|
357 continue;
|
danielebarchiesi@0
|
358 }
|
danielebarchiesi@0
|
359
|
danielebarchiesi@0
|
360 $valid = TRUE;
|
danielebarchiesi@0
|
361 if (!empty($info['type'])) {
|
danielebarchiesi@0
|
362 $valid = FALSE;
|
danielebarchiesi@0
|
363 if (empty($this->definition['validate type'])) {
|
danielebarchiesi@0
|
364 continue;
|
danielebarchiesi@0
|
365 }
|
danielebarchiesi@0
|
366 foreach ((array) $info['type'] as $type) {
|
danielebarchiesi@0
|
367 if ($type == $this->definition['validate type']) {
|
danielebarchiesi@0
|
368 $valid = TRUE;
|
danielebarchiesi@0
|
369 break;
|
danielebarchiesi@0
|
370 }
|
danielebarchiesi@0
|
371 }
|
danielebarchiesi@0
|
372 }
|
danielebarchiesi@0
|
373
|
danielebarchiesi@0
|
374 // If we decide this validator is ok, add it to the list.
|
danielebarchiesi@0
|
375 if ($valid) {
|
danielebarchiesi@0
|
376 $plugin = $this->get_plugin('argument validator', $id);
|
danielebarchiesi@0
|
377 if ($plugin) {
|
danielebarchiesi@0
|
378 if ($plugin->access() || $this->options['validate']['type'] == $id) {
|
danielebarchiesi@0
|
379 $form['validate']['options'][$id] = array(
|
danielebarchiesi@0
|
380 '#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
|
danielebarchiesi@0
|
381 '#suffix' => '</div>',
|
danielebarchiesi@0
|
382 '#type' => 'item',
|
danielebarchiesi@0
|
383 // Even if the plugin has no options add the key to the form_state.
|
danielebarchiesi@0
|
384 '#input' => TRUE, // trick it into checking input to make #process run
|
danielebarchiesi@0
|
385 '#dependency' => array(
|
danielebarchiesi@0
|
386 'edit-options-specify-validation' => array('1'),
|
danielebarchiesi@0
|
387 'edit-options-validate-type' => array($id),
|
danielebarchiesi@0
|
388 ),
|
danielebarchiesi@0
|
389 '#dependency_count' => 2,
|
danielebarchiesi@0
|
390 '#id' => 'edit-options-validate-options-' . $id,
|
danielebarchiesi@0
|
391 );
|
danielebarchiesi@0
|
392 $plugin->options_form($form['validate']['options'][$id], $form_state);
|
danielebarchiesi@0
|
393 $validate_types[$id] = $info['title'];
|
danielebarchiesi@0
|
394 }
|
danielebarchiesi@0
|
395 }
|
danielebarchiesi@0
|
396 }
|
danielebarchiesi@0
|
397 }
|
danielebarchiesi@0
|
398
|
danielebarchiesi@0
|
399 asort($validate_types);
|
danielebarchiesi@0
|
400 $form['validate']['type']['#options'] = $validate_types;
|
danielebarchiesi@0
|
401
|
danielebarchiesi@0
|
402 $form['validate']['fail'] = array(
|
danielebarchiesi@0
|
403 '#type' => 'select',
|
danielebarchiesi@0
|
404 '#title' => t('Action to take if filter value does not validate'),
|
danielebarchiesi@0
|
405 '#default_value' => $this->options['validate']['fail'],
|
danielebarchiesi@0
|
406 '#options' => $validate_options,
|
danielebarchiesi@0
|
407 '#dependency' => array(
|
danielebarchiesi@0
|
408 'edit-options-specify-validation' => array('1'),
|
danielebarchiesi@0
|
409 ),
|
danielebarchiesi@0
|
410 '#fieldset' => 'argument_present',
|
danielebarchiesi@0
|
411 );
|
danielebarchiesi@0
|
412 }
|
danielebarchiesi@0
|
413
|
danielebarchiesi@0
|
414 function options_validate(&$form, &$form_state) {
|
danielebarchiesi@0
|
415 if (empty($form_state['values']['options'])) {
|
danielebarchiesi@0
|
416 return;
|
danielebarchiesi@0
|
417 }
|
danielebarchiesi@0
|
418
|
danielebarchiesi@0
|
419 // Let the plugins do validation.
|
danielebarchiesi@0
|
420 $default_id = $form_state['values']['options']['default_argument_type'];
|
danielebarchiesi@0
|
421 $plugin = $this->get_plugin('argument default', $default_id);
|
danielebarchiesi@0
|
422 if ($plugin) {
|
danielebarchiesi@0
|
423 $plugin->options_validate($form['argument_default'][$default_id], $form_state, $form_state['values']['options']['argument_default'][$default_id]);
|
danielebarchiesi@0
|
424 }
|
danielebarchiesi@0
|
425
|
danielebarchiesi@0
|
426 // summary plugin
|
danielebarchiesi@0
|
427 $summary_id = $form_state['values']['options']['summary']['format'];
|
danielebarchiesi@0
|
428 $plugin = $this->get_plugin('style', $summary_id);
|
danielebarchiesi@0
|
429 if ($plugin) {
|
danielebarchiesi@0
|
430 $plugin->options_validate($form['summary']['options'][$summary_id], $form_state, $form_state['values']['options']['summary']['options'][$summary_id]);
|
danielebarchiesi@0
|
431 }
|
danielebarchiesi@0
|
432
|
danielebarchiesi@0
|
433 $validate_id = $form_state['values']['options']['validate']['type'];
|
danielebarchiesi@0
|
434 $plugin = $this->get_plugin('argument validator', $validate_id);
|
danielebarchiesi@0
|
435 if ($plugin) {
|
danielebarchiesi@0
|
436 $plugin->options_validate($form['validate']['options'][$default_id], $form_state, $form_state['values']['options']['validate']['options'][$validate_id]);
|
danielebarchiesi@0
|
437 }
|
danielebarchiesi@0
|
438
|
danielebarchiesi@0
|
439 }
|
danielebarchiesi@0
|
440
|
danielebarchiesi@0
|
441 function options_submit(&$form, &$form_state) {
|
danielebarchiesi@0
|
442 if (empty($form_state['values']['options'])) {
|
danielebarchiesi@0
|
443 return;
|
danielebarchiesi@0
|
444 }
|
danielebarchiesi@0
|
445
|
danielebarchiesi@0
|
446 // Let the plugins make submit modifications if necessary.
|
danielebarchiesi@0
|
447 $default_id = $form_state['values']['options']['default_argument_type'];
|
danielebarchiesi@0
|
448 $plugin = $this->get_plugin('argument default', $default_id);
|
danielebarchiesi@0
|
449 if ($plugin) {
|
danielebarchiesi@0
|
450 $options = &$form_state['values']['options']['argument_default'][$default_id];
|
danielebarchiesi@0
|
451 $plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
|
danielebarchiesi@0
|
452 // Copy the now submitted options to their final resting place so they get saved.
|
danielebarchiesi@0
|
453 $form_state['values']['options']['default_argument_options'] = $options;
|
danielebarchiesi@0
|
454 }
|
danielebarchiesi@0
|
455
|
danielebarchiesi@0
|
456 // summary plugin
|
danielebarchiesi@0
|
457 $summary_id = $form_state['values']['options']['summary']['format'];
|
danielebarchiesi@0
|
458 $plugin = $this->get_plugin('style', $summary_id);
|
danielebarchiesi@0
|
459 if ($plugin) {
|
danielebarchiesi@0
|
460 $options = &$form_state['values']['options']['summary']['options'][$summary_id];
|
danielebarchiesi@0
|
461 $plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options);
|
danielebarchiesi@0
|
462 // Copy the now submitted options to their final resting place so they get saved.
|
danielebarchiesi@0
|
463 $form_state['values']['options']['summary_options'] = $options;
|
danielebarchiesi@0
|
464 }
|
danielebarchiesi@0
|
465
|
danielebarchiesi@0
|
466 $validate_id = $form_state['values']['options']['validate']['type'];
|
danielebarchiesi@0
|
467 $plugin = $this->get_plugin('argument validator', $validate_id);
|
danielebarchiesi@0
|
468 if ($plugin) {
|
danielebarchiesi@0
|
469 $options = &$form_state['values']['options']['validate']['options'][$validate_id];
|
danielebarchiesi@0
|
470 $plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options);
|
danielebarchiesi@0
|
471 // Copy the now submitted options to their final resting place so they get saved.
|
danielebarchiesi@0
|
472 $form_state['values']['options']['validate_options'] = $options;
|
danielebarchiesi@0
|
473 }
|
danielebarchiesi@0
|
474
|
danielebarchiesi@0
|
475 // Clear out the content of title if it's not enabled.
|
danielebarchiesi@0
|
476 $options =& $form_state['values']['options'];
|
danielebarchiesi@0
|
477 if (empty($options['title_enable'])) {
|
danielebarchiesi@0
|
478 $options['title'] = '';
|
danielebarchiesi@0
|
479 }
|
danielebarchiesi@0
|
480 }
|
danielebarchiesi@0
|
481
|
danielebarchiesi@0
|
482 /**
|
danielebarchiesi@0
|
483 * Provide a list of default behaviors for this argument if the argument
|
danielebarchiesi@0
|
484 * is not present.
|
danielebarchiesi@0
|
485 *
|
danielebarchiesi@0
|
486 * Override this method to provide additional (or fewer) default behaviors.
|
danielebarchiesi@0
|
487 */
|
danielebarchiesi@0
|
488 function default_actions($which = NULL) {
|
danielebarchiesi@0
|
489 $defaults = array(
|
danielebarchiesi@0
|
490 'ignore' => array(
|
danielebarchiesi@0
|
491 'title' => t('Display all results for the specified field'),
|
danielebarchiesi@0
|
492 'method' => 'default_ignore',
|
danielebarchiesi@0
|
493 'breadcrumb' => TRUE, // generate a breadcrumb to here
|
danielebarchiesi@0
|
494 ),
|
danielebarchiesi@0
|
495 'default' => array(
|
danielebarchiesi@0
|
496 'title' => t('Provide default value'),
|
danielebarchiesi@0
|
497 'method' => 'default_default',
|
danielebarchiesi@0
|
498 'form method' => 'default_argument_form',
|
danielebarchiesi@0
|
499 'has default argument' => TRUE,
|
danielebarchiesi@0
|
500 'default only' => TRUE, // this can only be used for missing argument, not validation failure
|
danielebarchiesi@0
|
501 'breadcrumb' => TRUE, // generate a breadcrumb to here
|
danielebarchiesi@0
|
502 ),
|
danielebarchiesi@0
|
503 'not found' => array(
|
danielebarchiesi@0
|
504 'title' => t('Hide view'),
|
danielebarchiesi@0
|
505 'method' => 'default_not_found',
|
danielebarchiesi@0
|
506 'hard fail' => TRUE, // This is a hard fail condition
|
danielebarchiesi@0
|
507 ),
|
danielebarchiesi@0
|
508 'summary' => array(
|
danielebarchiesi@0
|
509 'title' => t('Display a summary'),
|
danielebarchiesi@0
|
510 'method' => 'default_summary',
|
danielebarchiesi@0
|
511 'form method' => 'default_summary_form',
|
danielebarchiesi@0
|
512 'style plugin' => TRUE,
|
danielebarchiesi@0
|
513 'breadcrumb' => TRUE, // generate a breadcrumb to here
|
danielebarchiesi@0
|
514 ),
|
danielebarchiesi@0
|
515 'empty' => array(
|
danielebarchiesi@0
|
516 'title' => t('Display contents of "No results found"'),
|
danielebarchiesi@0
|
517 'method' => 'default_empty',
|
danielebarchiesi@0
|
518 'breadcrumb' => TRUE, // generate a breadcrumb to here
|
danielebarchiesi@0
|
519 ),
|
danielebarchiesi@0
|
520 'access denied' => array(
|
danielebarchiesi@0
|
521 'title' => t('Display "Access Denied"'),
|
danielebarchiesi@0
|
522 'method' => 'default_access_denied',
|
danielebarchiesi@0
|
523 'breadcrumb' => FALSE, // generate a breadcrumb to here
|
danielebarchiesi@0
|
524 ),
|
danielebarchiesi@0
|
525 );
|
danielebarchiesi@0
|
526
|
danielebarchiesi@0
|
527 if ($this->view->display_handler->has_path()) {
|
danielebarchiesi@0
|
528 $defaults['not found']['title'] = t('Show "Page not found"');
|
danielebarchiesi@0
|
529 }
|
danielebarchiesi@0
|
530
|
danielebarchiesi@0
|
531 if ($which) {
|
danielebarchiesi@0
|
532 if (!empty($defaults[$which])) {
|
danielebarchiesi@0
|
533 return $defaults[$which];
|
danielebarchiesi@0
|
534 }
|
danielebarchiesi@0
|
535 }
|
danielebarchiesi@0
|
536 else {
|
danielebarchiesi@0
|
537 return $defaults;
|
danielebarchiesi@0
|
538 }
|
danielebarchiesi@0
|
539 }
|
danielebarchiesi@0
|
540
|
danielebarchiesi@0
|
541 /**
|
danielebarchiesi@0
|
542 * Provide a form for selecting the default argument when the
|
danielebarchiesi@0
|
543 * default action is set to provide default argument.
|
danielebarchiesi@0
|
544 */
|
danielebarchiesi@0
|
545 function default_argument_form(&$form, &$form_state) {
|
danielebarchiesi@0
|
546 $plugins = views_fetch_plugin_data('argument default');
|
danielebarchiesi@0
|
547 $options = array();
|
danielebarchiesi@0
|
548
|
danielebarchiesi@0
|
549 $form['default_argument_skip_url'] = array(
|
danielebarchiesi@0
|
550 '#type' => 'checkbox',
|
danielebarchiesi@0
|
551 '#title' => t('Skip default argument for view URL'),
|
danielebarchiesi@0
|
552 '#default_value' => $this->options['default_argument_skip_url'],
|
danielebarchiesi@0
|
553 '#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.')
|
danielebarchiesi@0
|
554 );
|
danielebarchiesi@0
|
555
|
danielebarchiesi@0
|
556 $form['default_argument_type'] = array(
|
danielebarchiesi@0
|
557 '#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
|
danielebarchiesi@0
|
558 '#suffix' => '</div>',
|
danielebarchiesi@0
|
559 '#type' => 'select',
|
danielebarchiesi@0
|
560 '#id' => 'edit-options-default-argument-type',
|
danielebarchiesi@0
|
561 '#title' => t('Type'),
|
danielebarchiesi@0
|
562 '#default_value' => $this->options['default_argument_type'],
|
danielebarchiesi@0
|
563
|
danielebarchiesi@0
|
564 '#dependency' => array('radio:options[default_action]' => array('default')),
|
danielebarchiesi@0
|
565 // Views custom key, moves this element to the appropriate container
|
danielebarchiesi@0
|
566 // under the radio button.
|
danielebarchiesi@0
|
567 '#argument_option' => 'default',
|
danielebarchiesi@0
|
568 );
|
danielebarchiesi@0
|
569
|
danielebarchiesi@0
|
570 foreach ($plugins as $id => $info) {
|
danielebarchiesi@0
|
571 if (!empty($info['no ui'])) {
|
danielebarchiesi@0
|
572 continue;
|
danielebarchiesi@0
|
573 }
|
danielebarchiesi@0
|
574 $plugin = $this->get_plugin('argument default', $id);
|
danielebarchiesi@0
|
575 if ($plugin) {
|
danielebarchiesi@0
|
576 if ($plugin->access() || $this->options['default_argument_type'] == $id) {
|
danielebarchiesi@0
|
577 $form['argument_default']['#argument_option'] = 'default';
|
danielebarchiesi@0
|
578 $form['argument_default'][$id] = array(
|
danielebarchiesi@0
|
579 '#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
|
danielebarchiesi@0
|
580 '#suffix' => '</div>',
|
danielebarchiesi@0
|
581 '#id' => 'edit-options-argument-default-options-' . $id,
|
danielebarchiesi@0
|
582 '#type' => 'item',
|
danielebarchiesi@0
|
583 // Even if the plugin has no options add the key to the form_state.
|
danielebarchiesi@0
|
584 '#input' => TRUE,
|
danielebarchiesi@0
|
585 '#dependency' => array(
|
danielebarchiesi@0
|
586 'radio:options[default_action]' => array('default'),
|
danielebarchiesi@0
|
587 'edit-options-default-argument-type' => array($id)
|
danielebarchiesi@0
|
588 ),
|
danielebarchiesi@0
|
589 '#dependency_count' => 2,
|
danielebarchiesi@0
|
590 );
|
danielebarchiesi@0
|
591 $options[$id] = $info['title'];
|
danielebarchiesi@0
|
592 $plugin->options_form($form['argument_default'][$id], $form_state);
|
danielebarchiesi@0
|
593 }
|
danielebarchiesi@0
|
594 }
|
danielebarchiesi@0
|
595 }
|
danielebarchiesi@0
|
596
|
danielebarchiesi@0
|
597 asort($options);
|
danielebarchiesi@0
|
598 $form['default_argument_type']['#options'] = $options;
|
danielebarchiesi@0
|
599 }
|
danielebarchiesi@0
|
600
|
danielebarchiesi@0
|
601 /**
|
danielebarchiesi@0
|
602 * Provide a form for selecting further summary options when the
|
danielebarchiesi@0
|
603 * default action is set to display one.
|
danielebarchiesi@0
|
604 */
|
danielebarchiesi@0
|
605 function default_summary_form(&$form, &$form_state) {
|
danielebarchiesi@0
|
606 $style_plugins = views_fetch_plugin_data('style');
|
danielebarchiesi@0
|
607 $summary_plugins = array();
|
danielebarchiesi@0
|
608 $format_options = array();
|
danielebarchiesi@0
|
609 foreach ($style_plugins as $key => $plugin) {
|
danielebarchiesi@0
|
610 if (isset($plugin['type']) && $plugin['type'] == 'summary') {
|
danielebarchiesi@0
|
611 $summary_plugins[$key] = $plugin;
|
danielebarchiesi@0
|
612 $format_options[$key] = $plugin['title'];
|
danielebarchiesi@0
|
613 }
|
danielebarchiesi@0
|
614 }
|
danielebarchiesi@0
|
615
|
danielebarchiesi@0
|
616 $form['summary'] = array(
|
danielebarchiesi@0
|
617 // Views custom key, moves this element to the appropriate container
|
danielebarchiesi@0
|
618 // under the radio button.
|
danielebarchiesi@0
|
619 '#argument_option' => 'summary',
|
danielebarchiesi@0
|
620 );
|
danielebarchiesi@0
|
621 $form['summary']['sort_order'] = array(
|
danielebarchiesi@0
|
622 '#type' => 'radios',
|
danielebarchiesi@0
|
623 '#title' => t('Sort order'),
|
danielebarchiesi@0
|
624 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
|
danielebarchiesi@0
|
625 '#default_value' => $this->options['summary']['sort_order'],
|
danielebarchiesi@0
|
626 '#dependency' => array('radio:options[default_action]' => array('summary')),
|
danielebarchiesi@0
|
627 );
|
danielebarchiesi@0
|
628 $form['summary']['number_of_records'] = array(
|
danielebarchiesi@0
|
629 '#type' => 'radios',
|
danielebarchiesi@0
|
630 '#title' => t('Sort by'),
|
danielebarchiesi@0
|
631 '#default_value' => $this->options['summary']['number_of_records'],
|
danielebarchiesi@0
|
632 '#options' => array(
|
danielebarchiesi@0
|
633 0 => $this->get_sort_name(),
|
danielebarchiesi@0
|
634 1 => t('Number of records')
|
danielebarchiesi@0
|
635 ),
|
danielebarchiesi@0
|
636 '#dependency' => array('radio:options[default_action]' => array('summary')),
|
danielebarchiesi@0
|
637 );
|
danielebarchiesi@0
|
638
|
danielebarchiesi@0
|
639 $form['summary']['format'] = array(
|
danielebarchiesi@0
|
640 '#type' => 'radios',
|
danielebarchiesi@0
|
641 '#title' => t('Format'),
|
danielebarchiesi@0
|
642 '#options' => $format_options,
|
danielebarchiesi@0
|
643 '#default_value' => $this->options['summary']['format'],
|
danielebarchiesi@0
|
644 '#dependency' => array('radio:options[default_action]' => array('summary')),
|
danielebarchiesi@0
|
645 );
|
danielebarchiesi@0
|
646
|
danielebarchiesi@0
|
647 foreach ($summary_plugins as $id => $info) {
|
danielebarchiesi@0
|
648 if (empty($info['uses options'])) {
|
danielebarchiesi@0
|
649 continue;
|
danielebarchiesi@0
|
650 }
|
danielebarchiesi@0
|
651 $plugin = $this->get_plugin('style', $id);
|
danielebarchiesi@0
|
652 if ($plugin) {
|
danielebarchiesi@0
|
653 $form['summary']['options'][$id] = array(
|
danielebarchiesi@0
|
654 '#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
|
danielebarchiesi@0
|
655 '#suffix' => '</div>',
|
danielebarchiesi@0
|
656 '#id' => 'edit-options-summary-options-' . $id,
|
danielebarchiesi@0
|
657 '#type' => 'item',
|
danielebarchiesi@0
|
658 '#input' => TRUE, // trick it into checking input to make #process run
|
danielebarchiesi@0
|
659 '#dependency' => array(
|
danielebarchiesi@0
|
660 'radio:options[default_action]' => array('summary'),
|
danielebarchiesi@0
|
661 'radio:options[summary][format]' => array($id),
|
danielebarchiesi@0
|
662 ),
|
danielebarchiesi@0
|
663 '#dependency_count' => 2,
|
danielebarchiesi@0
|
664 );
|
danielebarchiesi@0
|
665 $options[$id] = $info['title'];
|
danielebarchiesi@0
|
666 $plugin->options_form($form['summary']['options'][$id], $form_state);
|
danielebarchiesi@0
|
667 }
|
danielebarchiesi@0
|
668 }
|
danielebarchiesi@0
|
669 }
|
danielebarchiesi@0
|
670
|
danielebarchiesi@0
|
671 /**
|
danielebarchiesi@0
|
672 * Handle the default action, which means our argument wasn't present.
|
danielebarchiesi@0
|
673 *
|
danielebarchiesi@0
|
674 * Override this method only with extreme care.
|
danielebarchiesi@0
|
675 *
|
danielebarchiesi@0
|
676 * @return
|
danielebarchiesi@0
|
677 * A boolean value; if TRUE, continue building this view. If FALSE,
|
danielebarchiesi@0
|
678 * building the view will be aborted here.
|
danielebarchiesi@0
|
679 */
|
danielebarchiesi@0
|
680 function default_action($info = NULL) {
|
danielebarchiesi@0
|
681 if (!isset($info)) {
|
danielebarchiesi@0
|
682 $info = $this->default_actions($this->options['default_action']);
|
danielebarchiesi@0
|
683 }
|
danielebarchiesi@0
|
684
|
danielebarchiesi@0
|
685 if (!$info) {
|
danielebarchiesi@0
|
686 return FALSE;
|
danielebarchiesi@0
|
687 }
|
danielebarchiesi@0
|
688
|
danielebarchiesi@0
|
689 if (!empty($info['method args'])) {
|
danielebarchiesi@0
|
690 return call_user_func_array(array(&$this, $info['method']), $info['method args']);
|
danielebarchiesi@0
|
691 }
|
danielebarchiesi@0
|
692 else {
|
danielebarchiesi@0
|
693 return $this->{$info['method']}();
|
danielebarchiesi@0
|
694 }
|
danielebarchiesi@0
|
695 }
|
danielebarchiesi@0
|
696
|
danielebarchiesi@0
|
697 /**
|
danielebarchiesi@0
|
698 * How to act if validation failes
|
danielebarchiesi@0
|
699 */
|
danielebarchiesi@0
|
700 function validate_fail() {
|
danielebarchiesi@0
|
701 $info = $this->default_actions($this->options['validate']['fail']);
|
danielebarchiesi@0
|
702 return $this->default_action($info);
|
danielebarchiesi@0
|
703 }
|
danielebarchiesi@0
|
704 /**
|
danielebarchiesi@0
|
705 * Default action: ignore.
|
danielebarchiesi@0
|
706 *
|
danielebarchiesi@0
|
707 * If an argument was expected and was not given, in this case, simply
|
danielebarchiesi@0
|
708 * ignore the argument entirely.
|
danielebarchiesi@0
|
709 */
|
danielebarchiesi@0
|
710 function default_ignore() {
|
danielebarchiesi@0
|
711 return TRUE;
|
danielebarchiesi@0
|
712 }
|
danielebarchiesi@0
|
713
|
danielebarchiesi@0
|
714 /**
|
danielebarchiesi@0
|
715 * Default action: not found.
|
danielebarchiesi@0
|
716 *
|
danielebarchiesi@0
|
717 * If an argument was expected and was not given, in this case, report
|
danielebarchiesi@0
|
718 * the view as 'not found' or hide it.
|
danielebarchiesi@0
|
719 */
|
danielebarchiesi@0
|
720 function default_not_found() {
|
danielebarchiesi@0
|
721 // Set a failure condition and let the display manager handle it.
|
danielebarchiesi@0
|
722 $this->view->build_info['fail'] = TRUE;
|
danielebarchiesi@0
|
723 return FALSE;
|
danielebarchiesi@0
|
724 }
|
danielebarchiesi@0
|
725
|
danielebarchiesi@0
|
726 /**
|
danielebarchiesi@0
|
727 * Default action: access denied.
|
danielebarchiesi@0
|
728 *
|
danielebarchiesi@0
|
729 * If an argument was expected and was not given, in this case, report
|
danielebarchiesi@0
|
730 * the view as 'access denied'.
|
danielebarchiesi@0
|
731 */
|
danielebarchiesi@0
|
732 function default_access_denied() {
|
danielebarchiesi@0
|
733 $this->view->build_info['denied'] = TRUE;
|
danielebarchiesi@0
|
734 return FALSE;
|
danielebarchiesi@0
|
735 }
|
danielebarchiesi@0
|
736
|
danielebarchiesi@0
|
737 /**
|
danielebarchiesi@0
|
738 * Default action: empty
|
danielebarchiesi@0
|
739 *
|
danielebarchiesi@0
|
740 * If an argument was expected and was not given, in this case, display
|
danielebarchiesi@0
|
741 * the view's empty text
|
danielebarchiesi@0
|
742 */
|
danielebarchiesi@0
|
743 function default_empty() {
|
danielebarchiesi@0
|
744 // We return with no query; this will force the empty text.
|
danielebarchiesi@0
|
745 $this->view->built = TRUE;
|
danielebarchiesi@0
|
746 $this->view->executed = TRUE;
|
danielebarchiesi@0
|
747 $this->view->result = array();
|
danielebarchiesi@0
|
748 return FALSE;
|
danielebarchiesi@0
|
749 }
|
danielebarchiesi@0
|
750
|
danielebarchiesi@0
|
751 /**
|
danielebarchiesi@0
|
752 * This just returns true. The view argument builder will know where
|
danielebarchiesi@0
|
753 * to find the argument from.
|
danielebarchiesi@0
|
754 */
|
danielebarchiesi@0
|
755 function default_default() {
|
danielebarchiesi@0
|
756 return TRUE;
|
danielebarchiesi@0
|
757 }
|
danielebarchiesi@0
|
758
|
danielebarchiesi@0
|
759 /**
|
danielebarchiesi@0
|
760 * Determine if the argument is set to provide a default argument.
|
danielebarchiesi@0
|
761 */
|
danielebarchiesi@0
|
762 function has_default_argument() {
|
danielebarchiesi@0
|
763 $info = $this->default_actions($this->options['default_action']);
|
danielebarchiesi@0
|
764 return !empty($info['has default argument']);
|
danielebarchiesi@0
|
765 }
|
danielebarchiesi@0
|
766
|
danielebarchiesi@0
|
767 /**
|
danielebarchiesi@0
|
768 * Get a default argument, if available.
|
danielebarchiesi@0
|
769 */
|
danielebarchiesi@0
|
770 function get_default_argument() {
|
danielebarchiesi@0
|
771 $plugin = $this->get_plugin('argument default');
|
danielebarchiesi@0
|
772 if ($plugin) {
|
danielebarchiesi@0
|
773 return $plugin->get_argument();
|
danielebarchiesi@0
|
774 }
|
danielebarchiesi@0
|
775 }
|
danielebarchiesi@0
|
776
|
danielebarchiesi@0
|
777 /**
|
danielebarchiesi@0
|
778 * Process the summary arguments for display.
|
danielebarchiesi@0
|
779 *
|
danielebarchiesi@0
|
780 * For example, the validation plugin may want to alter an argument for use in
|
danielebarchiesi@0
|
781 * the URL.
|
danielebarchiesi@0
|
782 */
|
danielebarchiesi@0
|
783 function process_summary_arguments(&$args) {
|
danielebarchiesi@0
|
784 if ($this->options['validate']['type'] != 'none') {
|
danielebarchiesi@0
|
785 if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) {
|
danielebarchiesi@0
|
786 $this->validator->process_summary_arguments($args);
|
danielebarchiesi@0
|
787 }
|
danielebarchiesi@0
|
788 }
|
danielebarchiesi@0
|
789 }
|
danielebarchiesi@0
|
790
|
danielebarchiesi@0
|
791 /**
|
danielebarchiesi@0
|
792 * Default action: summary.
|
danielebarchiesi@0
|
793 *
|
danielebarchiesi@0
|
794 * If an argument was expected and was not given, in this case, display
|
danielebarchiesi@0
|
795 * a summary query.
|
danielebarchiesi@0
|
796 */
|
danielebarchiesi@0
|
797 function default_summary() {
|
danielebarchiesi@0
|
798 $this->view->build_info['summary'] = TRUE;
|
danielebarchiesi@0
|
799 $this->view->build_info['summary_level'] = $this->options['id'];
|
danielebarchiesi@0
|
800
|
danielebarchiesi@0
|
801 // Change the display style to the summary style for this
|
danielebarchiesi@0
|
802 // argument.
|
danielebarchiesi@0
|
803 $this->view->plugin_name = $this->options['summary']['format'];
|
danielebarchiesi@0
|
804 $this->view->style_options = $this->options['summary_options'];
|
danielebarchiesi@0
|
805
|
danielebarchiesi@0
|
806 // Clear out the normal primary field and whatever else may have
|
danielebarchiesi@0
|
807 // been added and let the summary do the work.
|
danielebarchiesi@0
|
808 $this->query->clear_fields();
|
danielebarchiesi@0
|
809 $this->summary_query();
|
danielebarchiesi@0
|
810
|
danielebarchiesi@0
|
811 $by = $this->options['summary']['number_of_records'] ? 'num_records' : NULL;
|
danielebarchiesi@0
|
812 $this->summary_sort($this->options['summary']['sort_order'], $by);
|
danielebarchiesi@0
|
813
|
danielebarchiesi@0
|
814 // Summaries have their own sorting and fields, so tell the View not
|
danielebarchiesi@0
|
815 // to build these.
|
danielebarchiesi@0
|
816 $this->view->build_sort = $this->view->build_fields = FALSE;
|
danielebarchiesi@0
|
817 return TRUE;
|
danielebarchiesi@0
|
818 }
|
danielebarchiesi@0
|
819
|
danielebarchiesi@0
|
820 /**
|
danielebarchiesi@0
|
821 * Build the info for the summary query.
|
danielebarchiesi@0
|
822 *
|
danielebarchiesi@0
|
823 * This must:
|
danielebarchiesi@0
|
824 * - add_groupby: group on this field in order to create summaries.
|
danielebarchiesi@0
|
825 * - add_field: add a 'num_nodes' field for the count. Usually it will
|
danielebarchiesi@0
|
826 * be a count on $view->base_field
|
danielebarchiesi@0
|
827 * - set_count_field: Reset the count field so we get the right paging.
|
danielebarchiesi@0
|
828 *
|
danielebarchiesi@0
|
829 * @return
|
danielebarchiesi@0
|
830 * The alias used to get the number of records (count) for this entry.
|
danielebarchiesi@0
|
831 */
|
danielebarchiesi@0
|
832 function summary_query() {
|
danielebarchiesi@0
|
833 $this->ensure_my_table();
|
danielebarchiesi@0
|
834 // Add the field.
|
danielebarchiesi@0
|
835 $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
|
danielebarchiesi@0
|
836
|
danielebarchiesi@0
|
837 $this->summary_name_field();
|
danielebarchiesi@0
|
838 return $this->summary_basics();
|
danielebarchiesi@0
|
839 }
|
danielebarchiesi@0
|
840
|
danielebarchiesi@0
|
841 /**
|
danielebarchiesi@0
|
842 * Add the name field, which is the field displayed in summary queries.
|
danielebarchiesi@0
|
843 * This is often used when the argument is numeric.
|
danielebarchiesi@0
|
844 */
|
danielebarchiesi@0
|
845 function summary_name_field() {
|
danielebarchiesi@0
|
846 // Add the 'name' field. For example, if this is a uid argument, the
|
danielebarchiesi@0
|
847 // name field would be 'name' (i.e, the username).
|
danielebarchiesi@0
|
848
|
danielebarchiesi@0
|
849 if (isset($this->name_table)) {
|
danielebarchiesi@0
|
850 // if the alias is different then we're probably added, not ensured,
|
danielebarchiesi@0
|
851 // so look up the join and add it instead.
|
danielebarchiesi@0
|
852 if ($this->table_alias != $this->name_table) {
|
danielebarchiesi@0
|
853 $j = views_get_table_join($this->name_table, $this->table);
|
danielebarchiesi@0
|
854 if ($j) {
|
danielebarchiesi@0
|
855 $join = clone $j;
|
danielebarchiesi@0
|
856 $join->left_table = $this->table_alias;
|
danielebarchiesi@0
|
857 $this->name_table_alias = $this->query->add_table($this->name_table, $this->relationship, $join);
|
danielebarchiesi@0
|
858 }
|
danielebarchiesi@0
|
859 }
|
danielebarchiesi@0
|
860 else {
|
danielebarchiesi@0
|
861 $this->name_table_alias = $this->query->ensure_table($this->name_table, $this->relationship);
|
danielebarchiesi@0
|
862 }
|
danielebarchiesi@0
|
863 }
|
danielebarchiesi@0
|
864 else {
|
danielebarchiesi@0
|
865 $this->name_table_alias = $this->table_alias;
|
danielebarchiesi@0
|
866 }
|
danielebarchiesi@0
|
867
|
danielebarchiesi@0
|
868 if (isset($this->name_field)) {
|
danielebarchiesi@0
|
869 $this->name_alias = $this->query->add_field($this->name_table_alias, $this->name_field);
|
danielebarchiesi@0
|
870 }
|
danielebarchiesi@0
|
871 else {
|
danielebarchiesi@0
|
872 $this->name_alias = $this->base_alias;
|
danielebarchiesi@0
|
873 }
|
danielebarchiesi@0
|
874 }
|
danielebarchiesi@0
|
875
|
danielebarchiesi@0
|
876 /**
|
danielebarchiesi@0
|
877 * Some basic summary behavior that doesn't need to be repeated as much as
|
danielebarchiesi@0
|
878 * code that goes into summary_query()
|
danielebarchiesi@0
|
879 */
|
danielebarchiesi@0
|
880 function summary_basics($count_field = TRUE) {
|
danielebarchiesi@0
|
881 // Add the number of nodes counter
|
danielebarchiesi@0
|
882 $distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct));
|
danielebarchiesi@0
|
883
|
danielebarchiesi@0
|
884 $count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records',
|
danielebarchiesi@0
|
885 array('count' => TRUE, 'distinct' => $distinct));
|
danielebarchiesi@0
|
886 $this->query->add_groupby($this->name_alias);
|
danielebarchiesi@0
|
887
|
danielebarchiesi@0
|
888 if ($count_field) {
|
danielebarchiesi@0
|
889 $this->query->set_count_field($this->table_alias, $this->real_field);
|
danielebarchiesi@0
|
890 }
|
danielebarchiesi@0
|
891
|
danielebarchiesi@0
|
892 $this->count_alias = $count_alias;
|
danielebarchiesi@0
|
893 }
|
danielebarchiesi@0
|
894
|
danielebarchiesi@0
|
895 /**
|
danielebarchiesi@0
|
896 * Sorts the summary based upon the user's selection. The base variant of
|
danielebarchiesi@0
|
897 * this is usually adequte.
|
danielebarchiesi@0
|
898 *
|
danielebarchiesi@0
|
899 * @param $order
|
danielebarchiesi@0
|
900 * The order selected in the UI.
|
danielebarchiesi@0
|
901 */
|
danielebarchiesi@0
|
902 function summary_sort($order, $by = NULL) {
|
danielebarchiesi@0
|
903 $this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias));
|
danielebarchiesi@0
|
904 }
|
danielebarchiesi@0
|
905
|
danielebarchiesi@0
|
906 /**
|
danielebarchiesi@0
|
907 * Provide the argument to use to link from the summary to the next level;
|
danielebarchiesi@0
|
908 * this will be called once per row of a summary, and used as part of
|
danielebarchiesi@0
|
909 * $view->get_url().
|
danielebarchiesi@0
|
910 *
|
danielebarchiesi@0
|
911 * @param $data
|
danielebarchiesi@0
|
912 * The query results for the row.
|
danielebarchiesi@0
|
913 */
|
danielebarchiesi@0
|
914 function summary_argument($data) {
|
danielebarchiesi@0
|
915 return $data->{$this->base_alias};
|
danielebarchiesi@0
|
916 }
|
danielebarchiesi@0
|
917
|
danielebarchiesi@0
|
918 /**
|
danielebarchiesi@0
|
919 * Provides the name to use for the summary. By default this is just
|
danielebarchiesi@0
|
920 * the name field.
|
danielebarchiesi@0
|
921 *
|
danielebarchiesi@0
|
922 * @param $data
|
danielebarchiesi@0
|
923 * The query results for the row.
|
danielebarchiesi@0
|
924 */
|
danielebarchiesi@0
|
925 function summary_name($data) {
|
danielebarchiesi@0
|
926 $value = $data->{$this->name_alias};
|
danielebarchiesi@0
|
927 if (empty($value) && !empty($this->definition['empty field name'])) {
|
danielebarchiesi@0
|
928 $value = $this->definition['empty field name'];
|
danielebarchiesi@0
|
929 }
|
danielebarchiesi@0
|
930 return check_plain($value);
|
danielebarchiesi@0
|
931 }
|
danielebarchiesi@0
|
932
|
danielebarchiesi@0
|
933 /**
|
danielebarchiesi@0
|
934 * Set up the query for this argument.
|
danielebarchiesi@0
|
935 *
|
danielebarchiesi@0
|
936 * The argument sent may be found at $this->argument.
|
danielebarchiesi@0
|
937 */
|
danielebarchiesi@0
|
938 function query($group_by = FALSE) {
|
danielebarchiesi@0
|
939 $this->ensure_my_table();
|
danielebarchiesi@0
|
940 $this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
|
danielebarchiesi@0
|
941 }
|
danielebarchiesi@0
|
942
|
danielebarchiesi@0
|
943 /**
|
danielebarchiesi@0
|
944 * Get the title this argument will assign the view, given the argument.
|
danielebarchiesi@0
|
945 *
|
danielebarchiesi@0
|
946 * This usually needs to be overridden to provide a proper title.
|
danielebarchiesi@0
|
947 */
|
danielebarchiesi@0
|
948 function title() {
|
danielebarchiesi@0
|
949 return check_plain($this->argument);
|
danielebarchiesi@0
|
950 }
|
danielebarchiesi@0
|
951
|
danielebarchiesi@0
|
952 /**
|
danielebarchiesi@0
|
953 * Called by the view object to get the title. This may be set by a
|
danielebarchiesi@0
|
954 * validator so we don't necessarily call through to title().
|
danielebarchiesi@0
|
955 */
|
danielebarchiesi@0
|
956 function get_title() {
|
danielebarchiesi@0
|
957 if (isset($this->validated_title)) {
|
danielebarchiesi@0
|
958 return $this->validated_title;
|
danielebarchiesi@0
|
959 }
|
danielebarchiesi@0
|
960 else {
|
danielebarchiesi@0
|
961 return $this->title();
|
danielebarchiesi@0
|
962 }
|
danielebarchiesi@0
|
963 }
|
danielebarchiesi@0
|
964
|
danielebarchiesi@0
|
965 /**
|
danielebarchiesi@0
|
966 * Validate that this argument works. By default, all arguments are valid.
|
danielebarchiesi@0
|
967 */
|
danielebarchiesi@0
|
968 function validate_arg($arg) {
|
danielebarchiesi@0
|
969 // By using % in URLs, arguments could be validated twice; this eases
|
danielebarchiesi@0
|
970 // that pain.
|
danielebarchiesi@0
|
971 if (isset($this->argument_validated)) {
|
danielebarchiesi@0
|
972 return $this->argument_validated;
|
danielebarchiesi@0
|
973 }
|
danielebarchiesi@0
|
974
|
danielebarchiesi@0
|
975 if ($this->is_exception($arg)) {
|
danielebarchiesi@0
|
976 return $this->argument_validated = TRUE;
|
danielebarchiesi@0
|
977 }
|
danielebarchiesi@0
|
978
|
danielebarchiesi@0
|
979 if ($this->options['validate']['type'] == 'none') {
|
danielebarchiesi@0
|
980 return $this->argument_validated = $this->validate_argument_basic($arg);
|
danielebarchiesi@0
|
981 }
|
danielebarchiesi@0
|
982
|
danielebarchiesi@0
|
983 $plugin = $this->get_plugin('argument validator');
|
danielebarchiesi@0
|
984 if ($plugin) {
|
danielebarchiesi@0
|
985 return $this->argument_validated = $plugin->validate_argument($arg);
|
danielebarchiesi@0
|
986 }
|
danielebarchiesi@0
|
987
|
danielebarchiesi@0
|
988 // If the plugin isn't found, fall back to the basic validation path:
|
danielebarchiesi@0
|
989 return $this->argument_validated = $this->validate_argument_basic($arg);
|
danielebarchiesi@0
|
990 }
|
danielebarchiesi@0
|
991
|
danielebarchiesi@0
|
992 /**
|
danielebarchiesi@0
|
993 * Called by the menu system to validate an argument.
|
danielebarchiesi@0
|
994 *
|
danielebarchiesi@0
|
995 * This checks to see if this is a 'soft fail', which means that if the
|
danielebarchiesi@0
|
996 * argument fails to validate, but there is an action to take anyway,
|
danielebarchiesi@0
|
997 * then validation cannot actually fail.
|
danielebarchiesi@0
|
998 */
|
danielebarchiesi@0
|
999 function validate_argument($arg) {
|
danielebarchiesi@0
|
1000 $validate_info = $this->default_actions($this->options['validate']['fail']);
|
danielebarchiesi@0
|
1001 if (empty($validate_info['hard fail'])) {
|
danielebarchiesi@0
|
1002 return TRUE;
|
danielebarchiesi@0
|
1003 }
|
danielebarchiesi@0
|
1004
|
danielebarchiesi@0
|
1005 $rc = $this->validate_arg($arg);
|
danielebarchiesi@0
|
1006
|
danielebarchiesi@0
|
1007 // If the validator has changed the validate fail condition to a
|
danielebarchiesi@0
|
1008 // soft fail, deal with that:
|
danielebarchiesi@0
|
1009 $validate_info = $this->default_actions($this->options['validate']['fail']);
|
danielebarchiesi@0
|
1010 if (empty($validate_info['hard fail'])) {
|
danielebarchiesi@0
|
1011 return TRUE;
|
danielebarchiesi@0
|
1012 }
|
danielebarchiesi@0
|
1013
|
danielebarchiesi@0
|
1014 return $rc;
|
danielebarchiesi@0
|
1015 }
|
danielebarchiesi@0
|
1016
|
danielebarchiesi@0
|
1017 /**
|
danielebarchiesi@0
|
1018 * Provide a basic argument validation.
|
danielebarchiesi@0
|
1019 *
|
danielebarchiesi@0
|
1020 * This can be overridden for more complex types; the basic
|
danielebarchiesi@0
|
1021 * validator only checks to see if the argument is not NULL
|
danielebarchiesi@0
|
1022 * or is numeric if the definition says it's numeric.
|
danielebarchiesi@0
|
1023 */
|
danielebarchiesi@0
|
1024 function validate_argument_basic($arg) {
|
danielebarchiesi@0
|
1025 if (!isset($arg) || $arg === '') {
|
danielebarchiesi@0
|
1026 return FALSE;
|
danielebarchiesi@0
|
1027 }
|
danielebarchiesi@0
|
1028
|
danielebarchiesi@0
|
1029 if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) {
|
danielebarchiesi@0
|
1030 return FALSE;
|
danielebarchiesi@0
|
1031 }
|
danielebarchiesi@0
|
1032
|
danielebarchiesi@0
|
1033 return TRUE;
|
danielebarchiesi@0
|
1034 }
|
danielebarchiesi@0
|
1035
|
danielebarchiesi@0
|
1036 /**
|
danielebarchiesi@0
|
1037 * Set the input for this argument
|
danielebarchiesi@0
|
1038 *
|
danielebarchiesi@0
|
1039 * @return TRUE if it successfully validates; FALSE if it does not.
|
danielebarchiesi@0
|
1040 */
|
danielebarchiesi@0
|
1041 function set_argument($arg) {
|
danielebarchiesi@0
|
1042 $this->argument = $arg;
|
danielebarchiesi@0
|
1043 return $this->validate_arg($arg);
|
danielebarchiesi@0
|
1044 }
|
danielebarchiesi@0
|
1045
|
danielebarchiesi@0
|
1046 /**
|
danielebarchiesi@0
|
1047 * Get the value of this argument.
|
danielebarchiesi@0
|
1048 */
|
danielebarchiesi@0
|
1049 function get_value() {
|
danielebarchiesi@0
|
1050 // If we already processed this argument, we're done.
|
danielebarchiesi@0
|
1051 if (isset($this->argument)) {
|
danielebarchiesi@0
|
1052 return $this->argument;
|
danielebarchiesi@0
|
1053 }
|
danielebarchiesi@0
|
1054
|
danielebarchiesi@0
|
1055 // Otherwise, we have to pretend to process ourself to find the value.
|
danielebarchiesi@0
|
1056 $value = NULL;
|
danielebarchiesi@0
|
1057 // Find the position of this argument within the view.
|
danielebarchiesi@0
|
1058 $position = 0;
|
danielebarchiesi@0
|
1059 foreach ($this->view->argument as $id => $argument) {
|
danielebarchiesi@0
|
1060 if ($id == $this->options['id']) {
|
danielebarchiesi@0
|
1061 break;
|
danielebarchiesi@0
|
1062 }
|
danielebarchiesi@0
|
1063 $position++;
|
danielebarchiesi@0
|
1064 }
|
danielebarchiesi@0
|
1065
|
danielebarchiesi@0
|
1066 $arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL;
|
danielebarchiesi@0
|
1067 $this->position = $position;
|
danielebarchiesi@0
|
1068
|
danielebarchiesi@0
|
1069 // Clone ourselves so that we don't break things when we're really
|
danielebarchiesi@0
|
1070 // processing the arguments.
|
danielebarchiesi@0
|
1071 $argument = clone $this;
|
danielebarchiesi@0
|
1072 if (!isset($arg) && $argument->has_default_argument()) {
|
danielebarchiesi@0
|
1073 $arg = $argument->get_default_argument();
|
danielebarchiesi@0
|
1074
|
danielebarchiesi@0
|
1075 // remember that this argument was computed, not passed on the URL.
|
danielebarchiesi@0
|
1076 $this->is_default = TRUE;
|
danielebarchiesi@0
|
1077 }
|
danielebarchiesi@0
|
1078 // Set the argument, which will also validate that the argument can be set.
|
danielebarchiesi@0
|
1079 if ($argument->set_argument($arg)) {
|
danielebarchiesi@0
|
1080 $value = $argument->argument;
|
danielebarchiesi@0
|
1081 }
|
danielebarchiesi@0
|
1082 unset($argument);
|
danielebarchiesi@0
|
1083 return $value;
|
danielebarchiesi@0
|
1084 }
|
danielebarchiesi@0
|
1085
|
danielebarchiesi@0
|
1086 /**
|
danielebarchiesi@0
|
1087 * Export handler for summary export.
|
danielebarchiesi@0
|
1088 *
|
danielebarchiesi@0
|
1089 * Arguments can have styles for the summary view. This special export
|
danielebarchiesi@0
|
1090 * handler makes sure this works properly.
|
danielebarchiesi@0
|
1091 */
|
danielebarchiesi@0
|
1092 function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
|
danielebarchiesi@0
|
1093 $output = '';
|
danielebarchiesi@0
|
1094 $name = $this->options['summary'][$option];
|
danielebarchiesi@0
|
1095 $options = $this->options['summary_options'];
|
danielebarchiesi@0
|
1096
|
danielebarchiesi@0
|
1097 $plugin = views_get_plugin('style', $name);
|
danielebarchiesi@0
|
1098 if ($plugin) {
|
danielebarchiesi@0
|
1099 $plugin->init($this->view, $this->view->display_handler->display, $options);
|
danielebarchiesi@0
|
1100 // Write which plugin to use.
|
danielebarchiesi@0
|
1101 $output .= $indent . $prefix . "['summary']['$option'] = '$name';\n";
|
danielebarchiesi@0
|
1102
|
danielebarchiesi@0
|
1103 // Pass off to the plugin to export itself.
|
danielebarchiesi@0
|
1104 $output .= $plugin->export_options($indent, $prefix . "['summary_options']");
|
danielebarchiesi@0
|
1105 }
|
danielebarchiesi@0
|
1106
|
danielebarchiesi@0
|
1107 return $output;
|
danielebarchiesi@0
|
1108 }
|
danielebarchiesi@0
|
1109
|
danielebarchiesi@0
|
1110 /**
|
danielebarchiesi@0
|
1111 * Export handler for validation export.
|
danielebarchiesi@0
|
1112 *
|
danielebarchiesi@0
|
1113 * Arguments use validation plugins. This special export handler makes sure
|
danielebarchiesi@0
|
1114 * this works properly.
|
danielebarchiesi@0
|
1115 */
|
danielebarchiesi@0
|
1116 function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
|
danielebarchiesi@0
|
1117 $output = '';
|
danielebarchiesi@0
|
1118 $name = $this->options['validate'][$option];
|
danielebarchiesi@0
|
1119 $options = $this->options['validate_options'];
|
danielebarchiesi@0
|
1120
|
danielebarchiesi@0
|
1121 $plugin = views_get_plugin('argument validator', $name);
|
danielebarchiesi@0
|
1122 if ($plugin) {
|
danielebarchiesi@0
|
1123 $plugin->init($this->view, $this->display, $options);
|
danielebarchiesi@0
|
1124 // Write which plugin to use.
|
danielebarchiesi@0
|
1125 $output .= $indent . $prefix . "['validate']['$option'] = '$name';\n";
|
danielebarchiesi@0
|
1126
|
danielebarchiesi@0
|
1127 // Pass off to the plugin to export itself.
|
danielebarchiesi@0
|
1128 $output .= $plugin->export_options($indent, $prefix . "['validate_options']");
|
danielebarchiesi@0
|
1129 }
|
danielebarchiesi@0
|
1130
|
danielebarchiesi@0
|
1131 return $output;
|
danielebarchiesi@0
|
1132 }
|
danielebarchiesi@0
|
1133
|
danielebarchiesi@0
|
1134 /**
|
danielebarchiesi@0
|
1135 * Generic plugin export handler.
|
danielebarchiesi@0
|
1136 *
|
danielebarchiesi@0
|
1137 * Since style and validation plugins have their own export handlers, this
|
danielebarchiesi@0
|
1138 * one is currently only used for default argument plugins.
|
danielebarchiesi@0
|
1139 */
|
danielebarchiesi@0
|
1140 function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
|
danielebarchiesi@0
|
1141 $output = '';
|
danielebarchiesi@0
|
1142 if ($option == 'default_argument_type') {
|
danielebarchiesi@0
|
1143 $type = 'argument default';
|
danielebarchiesi@0
|
1144 $option_name = 'default_argument_options';
|
danielebarchiesi@0
|
1145 }
|
danielebarchiesi@0
|
1146
|
danielebarchiesi@0
|
1147 $plugin = $this->get_plugin($type);
|
danielebarchiesi@0
|
1148 $name = $this->options[$option];
|
danielebarchiesi@0
|
1149
|
danielebarchiesi@0
|
1150 if ($plugin) {
|
danielebarchiesi@0
|
1151 // Write which plugin to use.
|
danielebarchiesi@0
|
1152 $output .= $indent . $prefix . "['$option'] = '$name';\n";
|
danielebarchiesi@0
|
1153
|
danielebarchiesi@0
|
1154 // Pass off to the plugin to export itself.
|
danielebarchiesi@0
|
1155 $output .= $plugin->export_options($indent, $prefix . "['$option_name']");
|
danielebarchiesi@0
|
1156 }
|
danielebarchiesi@0
|
1157
|
danielebarchiesi@0
|
1158 return $output;
|
danielebarchiesi@0
|
1159 }
|
danielebarchiesi@0
|
1160
|
danielebarchiesi@0
|
1161 /**
|
danielebarchiesi@0
|
1162 * Get the display or row plugin, if it exists.
|
danielebarchiesi@0
|
1163 */
|
danielebarchiesi@0
|
1164 function get_plugin($type = 'argument default', $name = NULL) {
|
danielebarchiesi@0
|
1165 $options = array();
|
danielebarchiesi@0
|
1166 switch ($type) {
|
danielebarchiesi@0
|
1167 case 'argument default':
|
danielebarchiesi@0
|
1168 $plugin_name = $this->options['default_argument_type'];
|
danielebarchiesi@0
|
1169 $options_name = 'default_argument_options';
|
danielebarchiesi@0
|
1170 break;
|
danielebarchiesi@0
|
1171 case 'argument validator':
|
danielebarchiesi@0
|
1172 $plugin_name = $this->options['validate']['type'];
|
danielebarchiesi@0
|
1173 $options_name = 'validate_options';
|
danielebarchiesi@0
|
1174 break;
|
danielebarchiesi@0
|
1175 case 'style':
|
danielebarchiesi@0
|
1176 $plugin_name = $this->options['summary']['format'];
|
danielebarchiesi@0
|
1177 $options_name = 'summary_options';
|
danielebarchiesi@0
|
1178 }
|
danielebarchiesi@0
|
1179
|
danielebarchiesi@0
|
1180 if (!$name) {
|
danielebarchiesi@0
|
1181 $name = $plugin_name;
|
danielebarchiesi@0
|
1182 }
|
danielebarchiesi@0
|
1183
|
danielebarchiesi@0
|
1184 // we only fetch the options if we're fetching the plugin actually
|
danielebarchiesi@0
|
1185 // in use.
|
danielebarchiesi@0
|
1186 if ($name == $plugin_name) {
|
danielebarchiesi@0
|
1187 $options = $this->options[$options_name];
|
danielebarchiesi@0
|
1188 }
|
danielebarchiesi@0
|
1189
|
danielebarchiesi@0
|
1190 $plugin = views_get_plugin($type, $name);
|
danielebarchiesi@0
|
1191 if ($plugin) {
|
danielebarchiesi@0
|
1192 // Style plugins expects different parameters as argument related plugins.
|
danielebarchiesi@0
|
1193 if ($type == 'style') {
|
danielebarchiesi@0
|
1194 $plugin->init($this->view, $this->view->display_handler->display, $options);
|
danielebarchiesi@0
|
1195 }
|
danielebarchiesi@0
|
1196 else {
|
danielebarchiesi@0
|
1197 $plugin->init($this->view, $this, $options);
|
danielebarchiesi@0
|
1198 }
|
danielebarchiesi@0
|
1199 return $plugin;
|
danielebarchiesi@0
|
1200 }
|
danielebarchiesi@0
|
1201 }
|
danielebarchiesi@0
|
1202
|
danielebarchiesi@0
|
1203 /**
|
danielebarchiesi@0
|
1204 * Return a description of how the argument would normally be sorted.
|
danielebarchiesi@0
|
1205 *
|
danielebarchiesi@0
|
1206 * Subclasses should override this to specify what the default sort order of
|
danielebarchiesi@0
|
1207 * their argument is (e.g. alphabetical, numeric, date).
|
danielebarchiesi@0
|
1208 */
|
danielebarchiesi@0
|
1209 function get_sort_name() {
|
danielebarchiesi@0
|
1210 return t('Default sort', array(), array('context' => 'Sort order'));
|
danielebarchiesi@0
|
1211 }
|
danielebarchiesi@0
|
1212 }
|
danielebarchiesi@0
|
1213
|
danielebarchiesi@0
|
1214 /**
|
danielebarchiesi@0
|
1215 * A special handler to take the place of missing or broken handlers.
|
danielebarchiesi@0
|
1216 *
|
danielebarchiesi@0
|
1217 * @ingroup views_argument_handlers
|
danielebarchiesi@0
|
1218 */
|
danielebarchiesi@0
|
1219 class views_handler_argument_broken extends views_handler_argument {
|
danielebarchiesi@0
|
1220 function ui_name($short = FALSE) {
|
danielebarchiesi@0
|
1221 return t('Broken/missing handler');
|
danielebarchiesi@0
|
1222 }
|
danielebarchiesi@0
|
1223
|
danielebarchiesi@0
|
1224 function ensure_my_table() { /* No table to ensure! */ }
|
danielebarchiesi@0
|
1225 function query($group_by = FALSE) { /* No query to run */ }
|
danielebarchiesi@0
|
1226 function options_form(&$form, &$form_state) {
|
danielebarchiesi@0
|
1227 $form['markup'] = array(
|
danielebarchiesi@0
|
1228 '#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
danielebarchiesi@0
|
1229 );
|
danielebarchiesi@0
|
1230 }
|
danielebarchiesi@0
|
1231
|
danielebarchiesi@0
|
1232 /**
|
danielebarchiesi@0
|
1233 * Determine if the handler is considered 'broken'
|
danielebarchiesi@0
|
1234 */
|
danielebarchiesi@0
|
1235 function broken() { return TRUE; }
|
danielebarchiesi@0
|
1236 }
|
danielebarchiesi@0
|
1237
|
danielebarchiesi@0
|
1238 /**
|
danielebarchiesi@0
|
1239 * @}
|
danielebarchiesi@0
|
1240 */
|