1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
interface ViewsWizardInterface {
|
12
|
function __construct($plugin);
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
function build_form($form, &$form_state);
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
function validate($form, &$form_state);
|
25
|
|
26
|
|
27
|
|
28
|
|
29
|
|
30
|
|
31
|
|
32
|
|
33
|
function create_view($form, &$form_state);
|
34
|
}
|
35
|
|
36
|
|
37
|
|
38
|
|
39
|
class ViewsWizardException extends Exception {
|
40
|
}
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
46
|
protected $base_table;
|
47
|
protected $entity_type;
|
48
|
protected $entity_info = array();
|
49
|
protected $validated_views = array();
|
50
|
protected $plugin = array();
|
51
|
protected $filter_defaults = array(
|
52
|
'id' => NULL,
|
53
|
'expose' => array('operator' => FALSE),
|
54
|
'group' => 1,
|
55
|
);
|
56
|
|
57
|
function __construct($plugin) {
|
58
|
$this->base_table = $plugin['base_table'];
|
59
|
$default = $this->filter_defaults;
|
60
|
|
61
|
if (isset($plugin['filters'])) {
|
62
|
foreach ($plugin['filters'] as $name => $info) {
|
63
|
$default['id'] = $name;
|
64
|
$plugin['filters'][$name] = $info + $default;
|
65
|
}
|
66
|
}
|
67
|
|
68
|
$this->plugin = $plugin;
|
69
|
|
70
|
$entities = entity_get_info();
|
71
|
foreach ($entities as $entity_type => $entity_info) {
|
72
|
if (isset($entity_info['base table']) && $this->base_table == $entity_info['base table']) {
|
73
|
$this->entity_info = $entity_info;
|
74
|
$this->entity_type = $entity_type;
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
|
79
|
function build_form($form, &$form_state) {
|
80
|
$style_options = views_fetch_plugin_names('style', 'normal', array($this->base_table));
|
81
|
$feed_row_options = views_fetch_plugin_names('row', 'feed', array($this->base_table));
|
82
|
$path_prefix = url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=');
|
83
|
|
84
|
|
85
|
$this->build_filters($form, $form_state);
|
86
|
$this->build_sorts($form, $form_state);
|
87
|
|
88
|
$form['displays']['page'] = array(
|
89
|
'#type' => 'fieldset',
|
90
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
91
|
'#tree' => TRUE,
|
92
|
);
|
93
|
$form['displays']['page']['create'] = array(
|
94
|
'#title' => t('Create a page'),
|
95
|
'#type' => 'checkbox',
|
96
|
'#attributes' => array('class' => array('strong')),
|
97
|
'#default_value' => TRUE,
|
98
|
'#id' => 'edit-page-create',
|
99
|
);
|
100
|
|
101
|
|
102
|
|
103
|
$form['displays']['page']['options'] = array(
|
104
|
'#type' => 'container',
|
105
|
'#attributes' => array('class' => array('options-set'),),
|
106
|
'#dependency' => array(
|
107
|
'edit-page-create' => array(1),
|
108
|
),
|
109
|
'#pre_render' => array('ctools_dependent_pre_render'),
|
110
|
'#prefix' => '<div><div id="edit-page-wrapper">',
|
111
|
'#suffix' => '</div></div>',
|
112
|
'#parents' => array('page'),
|
113
|
);
|
114
|
|
115
|
$form['displays']['page']['options']['title'] = array(
|
116
|
'#title' => t('Page title'),
|
117
|
'#type' => 'textfield',
|
118
|
);
|
119
|
$form['displays']['page']['options']['path'] = array(
|
120
|
'#title' => t('Path'),
|
121
|
'#type' => 'textfield',
|
122
|
'#field_prefix' => $path_prefix,
|
123
|
);
|
124
|
$form['displays']['page']['options']['style'] = array(
|
125
|
'#type' => 'fieldset',
|
126
|
'#attributes' => array('class' => array('container-inline', 'fieldset-no-legend')),
|
127
|
);
|
128
|
|
129
|
|
130
|
$form['displays']['page']['options']['style']['style_plugin'] = array(
|
131
|
'#title' => t('Display format'),
|
132
|
'#help_topic' => 'style',
|
133
|
'#type' => 'select',
|
134
|
'#options' => $style_options,
|
135
|
);
|
136
|
$style_form = &$form['displays']['page']['options']['style'];
|
137
|
$style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array('page', 'style', 'style_plugin'), 'default', $style_form['style_plugin']);
|
138
|
|
139
|
|
140
|
views_ui_add_ajax_trigger($style_form, 'style_plugin', array('displays', 'page', 'options'));
|
141
|
|
142
|
$this->build_form_style($form, $form_state, 'page');
|
143
|
$form['displays']['page']['options']['items_per_page'] = array(
|
144
|
'#title' => t('Items to display'),
|
145
|
'#type' => 'textfield',
|
146
|
'#default_value' => '10',
|
147
|
'#size' => 5,
|
148
|
'#element_validate' => array('views_element_validate_integer'),
|
149
|
);
|
150
|
$form['displays']['page']['options']['pager'] = array(
|
151
|
'#title' => t('Use a pager'),
|
152
|
'#type' => 'checkbox',
|
153
|
'#default_value' => TRUE,
|
154
|
);
|
155
|
$form['displays']['page']['options']['link'] = array(
|
156
|
'#title' => t('Create a menu link'),
|
157
|
'#type' => 'checkbox',
|
158
|
'#id' => 'edit-page-link',
|
159
|
);
|
160
|
$form['displays']['page']['options']['link_properties'] = array(
|
161
|
'#type' => 'container',
|
162
|
'#dependency' => array(
|
163
|
'edit-page-link' => array(1),
|
164
|
),
|
165
|
'#pre_render' => array('ctools_dependent_pre_render'),
|
166
|
'#prefix' => '<div id="edit-page-link-properties-wrapper">',
|
167
|
'#suffix' => '</div>',
|
168
|
);
|
169
|
if (module_exists('menu')) {
|
170
|
$menu_options = menu_get_menus();
|
171
|
}
|
172
|
else {
|
173
|
|
174
|
$menu_options = menu_list_system_menus();
|
175
|
foreach ($menu_options as $name => $title) {
|
176
|
$menu_options[$name] = t($title);
|
177
|
}
|
178
|
}
|
179
|
$form['displays']['page']['options']['link_properties']['menu_name'] = array(
|
180
|
'#title' => t('Menu'),
|
181
|
'#type' => 'select',
|
182
|
'#options' => $menu_options,
|
183
|
);
|
184
|
$form['displays']['page']['options']['link_properties']['title'] = array(
|
185
|
'#title' => t('Link text'),
|
186
|
'#type' => 'textfield',
|
187
|
);
|
188
|
|
189
|
if ($feed_row_options) {
|
190
|
$form['displays']['page']['options']['feed'] = array(
|
191
|
'#title' => t('Include an RSS feed'),
|
192
|
'#type' => 'checkbox',
|
193
|
'#id' => 'edit-page-feed',
|
194
|
);
|
195
|
$form['displays']['page']['options']['feed_properties'] = array(
|
196
|
'#type' => 'container',
|
197
|
'#dependency' => array(
|
198
|
'edit-page-feed' => array(1),
|
199
|
),
|
200
|
'#pre_render' => array('ctools_dependent_pre_render'),
|
201
|
'#prefix' => '<div id="edit-page-feed-properties-wrapper">',
|
202
|
'#suffix' => '</div>',
|
203
|
);
|
204
|
$form['displays']['page']['options']['feed_properties']['path'] = array(
|
205
|
'#title' => t('Feed path'),
|
206
|
'#type' => 'textfield',
|
207
|
'#field_prefix' => $path_prefix,
|
208
|
);
|
209
|
|
210
|
$form['displays']['page']['options']['feed_properties']['row_plugin'] = array(
|
211
|
'#title' => t('Feed row style'),
|
212
|
'#type' => 'select',
|
213
|
'#options' => $feed_row_options,
|
214
|
'#default_value' => key($feed_row_options),
|
215
|
'#access' => (count($feed_row_options) > 1),
|
216
|
'#dependency' => array(
|
217
|
'edit-page-feed' => array(1),
|
218
|
),
|
219
|
'#pre_render' => array('ctools_dependent_pre_render'),
|
220
|
'#prefix' => '<div id="edit-page-feed-properties-row-plugin-wrapper">',
|
221
|
'#suffix' => '</div>',
|
222
|
);
|
223
|
}
|
224
|
|
225
|
$form['displays']['block'] = array(
|
226
|
'#type' => 'fieldset',
|
227
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
228
|
'#tree' => TRUE,
|
229
|
);
|
230
|
$form['displays']['block']['create'] = array(
|
231
|
'#title' => t('Create a block'),
|
232
|
'#type' => 'checkbox',
|
233
|
'#attributes' => array('class' => array('strong')),
|
234
|
'#id' => 'edit-block-create',
|
235
|
);
|
236
|
|
237
|
|
238
|
|
239
|
$form['displays']['block']['options'] = array(
|
240
|
'#type' => 'container',
|
241
|
'#attributes' => array('class' => array('options-set'),),
|
242
|
'#dependency' => array(
|
243
|
'edit-block-create' => array(1),
|
244
|
),
|
245
|
'#pre_render' => array('ctools_dependent_pre_render'),
|
246
|
'#prefix' => '<div id="edit-block-wrapper">',
|
247
|
'#suffix' => '</div>',
|
248
|
'#parents' => array('block'),
|
249
|
);
|
250
|
|
251
|
$form['displays']['block']['options']['title'] = array(
|
252
|
'#title' => t('Block title'),
|
253
|
'#type' => 'textfield',
|
254
|
);
|
255
|
$form['displays']['block']['options']['style'] = array(
|
256
|
'#type' => 'fieldset',
|
257
|
'#attributes' => array('class' => array('container-inline', 'fieldset-no-legend')),
|
258
|
);
|
259
|
|
260
|
|
261
|
$form['displays']['block']['options']['style']['style_plugin'] = array(
|
262
|
'#title' => t('Display format'),
|
263
|
'#help_topic' => 'style',
|
264
|
'#type' => 'select',
|
265
|
'#options' => $style_options,
|
266
|
);
|
267
|
$style_form = &$form['displays']['block']['options']['style'];
|
268
|
$style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array('block', 'style', 'style_plugin'), 'default', $style_form['style_plugin']);
|
269
|
|
270
|
|
271
|
views_ui_add_ajax_trigger($style_form, 'style_plugin', array('displays', 'block', 'options'));
|
272
|
|
273
|
$this->build_form_style($form, $form_state, 'block');
|
274
|
$form['displays']['block']['options']['items_per_page'] = array(
|
275
|
'#title' => t('Items per page'),
|
276
|
'#type' => 'textfield',
|
277
|
'#default_value' => '5',
|
278
|
'#size' => 5,
|
279
|
'#element_validate' => array('views_element_validate_integer'),
|
280
|
);
|
281
|
$form['displays']['block']['options']['pager'] = array(
|
282
|
'#title' => t('Use a pager'),
|
283
|
'#type' => 'checkbox',
|
284
|
'#default_value' => FALSE,
|
285
|
);
|
286
|
|
287
|
return $form;
|
288
|
}
|
289
|
|
290
|
|
291
|
|
292
|
|
293
|
protected function build_form_style(&$form, &$form_state, $type) {
|
294
|
$style_form =& $form['displays'][$type]['options']['style'];
|
295
|
$style = $style_form['style_plugin']['#default_value'];
|
296
|
$style_plugin = views_get_plugin('style', $style);
|
297
|
if (isset($style_plugin) && $style_plugin->uses_row_plugin()) {
|
298
|
$options = $this->row_style_options($type);
|
299
|
$style_form['row_plugin'] = array(
|
300
|
'#type' => 'select',
|
301
|
'#title' => t('of'),
|
302
|
'#options' => $options,
|
303
|
'#access' => count($options) > 1,
|
304
|
);
|
305
|
|
306
|
|
307
|
$block_with_linked_titles_available = ($type == 'block' && isset($options['titles_linked']));
|
308
|
$default_value = $block_with_linked_titles_available ? 'titles_linked' : key($options);
|
309
|
$style_form['row_plugin']['#default_value'] = views_ui_get_selected($form_state, array($type, 'style', 'row_plugin'), $default_value, $style_form['row_plugin']);
|
310
|
|
311
|
views_ui_add_ajax_trigger($style_form, 'row_plugin', array('displays', $type, 'options', 'style', 'row_options'));
|
312
|
|
313
|
|
314
|
|
315
|
$style_form['row_options'] = array(
|
316
|
'#theme_wrappers' => array('container'),
|
317
|
);
|
318
|
}
|
319
|
elseif ($style_plugin->uses_fields()) {
|
320
|
$style_form['row_plugin'] = array('#markup' => '<span>' . t('of fields') . '</span>');
|
321
|
}
|
322
|
}
|
323
|
|
324
|
|
325
|
|
326
|
|
327
|
|
328
|
|
329
|
protected function row_style_options($type) {
|
330
|
$data = views_fetch_data($this->base_table);
|
331
|
|
332
|
$options = views_fetch_plugin_names('row', 'normal', array($this->base_table));
|
333
|
return $options;
|
334
|
}
|
335
|
|
336
|
|
337
|
|
338
|
|
339
|
|
340
|
|
341
|
|
342
|
protected function build_filters(&$form, &$form_state) {
|
343
|
|
344
|
$fields = views_fetch_fields($this->base_table, 'filter');
|
345
|
|
346
|
$entity_info = $this->entity_info;
|
347
|
|
348
|
if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) {
|
349
|
|
350
|
$options = array('all' => t('All'));
|
351
|
foreach ($entity_info['bundles'] as $type => $bundle) {
|
352
|
$options[$type] = $bundle['label'];
|
353
|
}
|
354
|
$form['displays']['show']['type'] = array(
|
355
|
'#type' => 'select',
|
356
|
'#title' => t('of type'),
|
357
|
'#options' => $options,
|
358
|
);
|
359
|
$selected_bundle = views_ui_get_selected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
|
360
|
$form['displays']['show']['type']['#default_value'] = $selected_bundle;
|
361
|
|
362
|
|
363
|
|
364
|
views_ui_add_ajax_trigger($form['displays']['show'], 'type', array('displays'));
|
365
|
}
|
366
|
|
367
|
|
368
|
|
369
|
|
370
|
|
371
|
|
372
|
|
373
|
|
374
|
|
375
|
|
376
|
|
377
|
|
378
|
|
379
|
|
380
|
|
381
|
if (isset($fields['taxonomy_index.tid'])) {
|
382
|
|
383
|
if (!empty($entity_info['fieldable'])) {
|
384
|
|
385
|
|
386
|
|
387
|
|
388
|
$bundles = array_keys($entity_info['bundles']);
|
389
|
|
390
|
|
391
|
if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
|
392
|
$bundles = array($selected_bundle);
|
393
|
}
|
394
|
$tag_fields = array();
|
395
|
foreach ($bundles as $bundle) {
|
396
|
foreach (field_info_instances($this->entity_type, $bundle) as $instance) {
|
397
|
|
398
|
|
399
|
if ($instance['widget']['type'] == 'taxonomy_autocomplete') {
|
400
|
$tag_fields[] = $instance['field_name'];
|
401
|
}
|
402
|
}
|
403
|
}
|
404
|
$tag_fields = array_unique($tag_fields);
|
405
|
if (!empty($tag_fields)) {
|
406
|
|
407
|
|
408
|
|
409
|
|
410
|
|
411
|
|
412
|
if (in_array('field_tags', $tag_fields)) {
|
413
|
$tag_field_name = 'field_tags';
|
414
|
}
|
415
|
else {
|
416
|
$tag_field_name = reset($tag_fields);
|
417
|
}
|
418
|
|
419
|
$form['displays']['show']['tagged_with'] = array(
|
420
|
'#type' => 'textfield',
|
421
|
'#title' => t('tagged with'),
|
422
|
'#autocomplete_path' => 'taxonomy/autocomplete/' . $tag_field_name,
|
423
|
'#size' => 30,
|
424
|
'#maxlength' => 1024,
|
425
|
'#field_name' => $tag_field_name,
|
426
|
'#element_validate' => array('views_ui_taxonomy_autocomplete_validate'),
|
427
|
);
|
428
|
}
|
429
|
}
|
430
|
}
|
431
|
}
|
432
|
|
433
|
|
434
|
|
435
|
|
436
|
|
437
|
|
438
|
protected function build_sorts(&$form, &$form_state) {
|
439
|
$sorts = array(
|
440
|
'none' => t('Unsorted'),
|
441
|
);
|
442
|
|
443
|
if (!empty($this->plugin['created_column'])) {
|
444
|
$sorts += array(
|
445
|
$this->plugin['created_column'] . ':DESC' => t('Newest first'),
|
446
|
$this->plugin['created_column'] . ':ASC' => t('Oldest first'),
|
447
|
);
|
448
|
}
|
449
|
if (isset($this->plugin['available_sorts'])) {
|
450
|
$sorts += $this->plugin['available_sorts'];
|
451
|
}
|
452
|
|
453
|
|
454
|
if (!empty($sorts)) {
|
455
|
$form['displays']['show']['sort'] = array(
|
456
|
'#type' => 'select',
|
457
|
'#title' => t('sorted by'),
|
458
|
'#options' => $sorts,
|
459
|
'#default_value' => isset($this->plugin['created_column']) ? $this->plugin['created_column'] . ':DESC' : 'none',
|
460
|
);
|
461
|
}
|
462
|
}
|
463
|
|
464
|
protected function instantiate_view($form, &$form_state) {
|
465
|
|
466
|
$view = views_new_view();
|
467
|
$view->name = $form_state['values']['name'];
|
468
|
$view->human_name = $form_state['values']['human_name'];
|
469
|
$view->description = $form_state['values']['description'];
|
470
|
$view->tag = 'default';
|
471
|
$view->core = VERSION;
|
472
|
$view->base_table = $this->base_table;
|
473
|
|
474
|
|
475
|
$display_options = $this->build_display_options($form, $form_state);
|
476
|
|
477
|
|
478
|
|
479
|
|
480
|
$this->alter_display_options($display_options, $form, $form_state);
|
481
|
|
482
|
$this->add_displays($view, $display_options, $form, $form_state);
|
483
|
|
484
|
return $view;
|
485
|
}
|
486
|
|
487
|
|
488
|
|
489
|
|
490
|
|
491
|
|
492
|
|
493
|
|
494
|
protected function build_display_options($form, $form_state) {
|
495
|
|
496
|
$display_options['default'] = $this->default_display_options($form, $form_state);
|
497
|
$display_options['default'] += array(
|
498
|
'filters' => array(),
|
499
|
'sorts' => array(),
|
500
|
);
|
501
|
$display_options['default']['filters'] += $this->default_display_filters($form, $form_state);
|
502
|
$display_options['default']['sorts'] += $this->default_display_sorts($form, $form_state);
|
503
|
|
504
|
|
505
|
if (!empty($form_state['values']['page']['create'])) {
|
506
|
$display_options['page'] = $this->page_display_options($form, $form_state);
|
507
|
|
508
|
|
509
|
if (!empty($form_state['values']['page']['feed'])) {
|
510
|
$display_options['feed'] = $this->page_feed_display_options($form, $form_state);
|
511
|
}
|
512
|
}
|
513
|
|
514
|
|
515
|
if (!empty($form_state['values']['block']['create'])) {
|
516
|
$display_options['block'] = $this->block_display_options($form, $form_state);
|
517
|
}
|
518
|
|
519
|
return $display_options;
|
520
|
}
|
521
|
|
522
|
|
523
|
|
524
|
|
525
|
protected function alter_display_options(&$display_options, $form, $form_state) {
|
526
|
|
527
|
|
528
|
|
529
|
if (isset($this->plugin['path_field'])) {
|
530
|
$path_field = $this->plugin['path_field'];
|
531
|
$path_fields_added = FALSE;
|
532
|
foreach ($display_options as $display_type => $options) {
|
533
|
if (!empty($options['style_plugin']) && $options['style_plugin'] == 'jump_menu') {
|
534
|
|
535
|
|
536
|
if (!$path_fields_added) {
|
537
|
|
538
|
|
539
|
|
540
|
|
541
|
$path_fields = !empty($this->plugin['path_fields_supplemental']) ? $this->plugin['path_fields_supplemental'] : array();
|
542
|
$path_fields[] = &$path_field;
|
543
|
|
544
|
|
545
|
|
546
|
foreach ($path_fields as &$field) {
|
547
|
$field['id'] = view::generate_item_id($field['id'], $display_options['default']['fields']);
|
548
|
$display_options['default']['fields'][$field['id']] = $field;
|
549
|
}
|
550
|
|
551
|
$path_fields_added = TRUE;
|
552
|
}
|
553
|
|
554
|
|
555
|
|
556
|
$display_options[$display_type]['style_options']['path'] = $path_field['id'];
|
557
|
}
|
558
|
}
|
559
|
}
|
560
|
|
561
|
|
562
|
|
563
|
foreach ($display_options as &$options) {
|
564
|
if ($options['style_plugin'] == 'table') {
|
565
|
foreach ($display_options['default']['fields'] as &$field) {
|
566
|
unset($field['label']);
|
567
|
}
|
568
|
}
|
569
|
}
|
570
|
}
|
571
|
|
572
|
|
573
|
|
574
|
|
575
|
protected function add_displays($view, $display_options, $form, $form_state) {
|
576
|
|
577
|
$default_display = $view->new_display('default', 'Master', 'default');
|
578
|
foreach ($display_options['default'] as $option => $value) {
|
579
|
$default_display->set_option($option, $value);
|
580
|
}
|
581
|
|
582
|
|
583
|
if (isset($display_options['page'])) {
|
584
|
$display = $view->new_display('page', 'Page', 'page');
|
585
|
|
586
|
|
587
|
|
588
|
$this->set_default_options($display_options['page'], $display, $default_display);
|
589
|
|
590
|
|
591
|
if (isset($display_options['feed'])) {
|
592
|
$display = $view->new_display('feed', 'Feed', 'feed');
|
593
|
$this->set_override_options($display_options['feed'], $display, $default_display);
|
594
|
}
|
595
|
}
|
596
|
|
597
|
|
598
|
if (isset($display_options['block'])) {
|
599
|
$display = $view->new_display('block', 'Block', 'block');
|
600
|
|
601
|
|
602
|
if (!isset($display_options['page'])) {
|
603
|
$this->set_default_options($display_options['block'], $display, $default_display);
|
604
|
}
|
605
|
else {
|
606
|
$this->set_override_options($display_options['block'], $display, $default_display);
|
607
|
}
|
608
|
}
|
609
|
}
|
610
|
|
611
|
|
612
|
|
613
|
|
614
|
|
615
|
protected function default_display_options($form, $form_state) {
|
616
|
$display_options = array();
|
617
|
$display_options['access']['type'] = 'none';
|
618
|
$display_options['cache']['type'] = 'none';
|
619
|
$display_options['query']['type'] = 'views_query';
|
620
|
$display_options['exposed_form']['type'] = 'basic';
|
621
|
$display_options['pager']['type'] = 'full';
|
622
|
$display_options['style_plugin'] = 'default';
|
623
|
$display_options['row_plugin'] = 'fields';
|
624
|
|
625
|
|
626
|
|
627
|
|
628
|
$data = views_fetch_data($this->base_table);
|
629
|
if (isset($data['table']['base']['defaults']['field'])) {
|
630
|
$field = $data['table']['base']['defaults']['field'];
|
631
|
}
|
632
|
else {
|
633
|
foreach ($data as $field => $field_data) {
|
634
|
if (isset($field_data['field']['handler'])) {
|
635
|
break;
|
636
|
}
|
637
|
}
|
638
|
}
|
639
|
$display_options['fields'][$field] = array(
|
640
|
'table' => $this->base_table,
|
641
|
'field' => $field,
|
642
|
'id' => $field,
|
643
|
);
|
644
|
|
645
|
return $display_options;
|
646
|
}
|
647
|
|
648
|
protected function default_display_filters($form, $form_state) {
|
649
|
$filters = array();
|
650
|
|
651
|
|
652
|
if (isset($this->plugin['filters'])) {
|
653
|
foreach ($this->plugin['filters'] as $name => $info) {
|
654
|
$filters[$name] = $info;
|
655
|
}
|
656
|
}
|
657
|
|
658
|
|
659
|
$filters = array_merge($filters, $this->default_display_filters_user($form, $form_state));
|
660
|
|
661
|
return $filters;
|
662
|
}
|
663
|
|
664
|
protected function default_display_filters_user($form, $form_state) {
|
665
|
$filters = array();
|
666
|
|
667
|
if (!empty($form_state['values']['show']['type']) && $form_state['values']['show']['type'] != 'all') {
|
668
|
$bundle_key = $this->entity_info['bundle keys']['bundle'];
|
669
|
|
670
|
|
671
|
|
672
|
$fields = views_fetch_fields($this->base_table, 'filter');
|
673
|
if (isset($fields[$this->base_table . '.' . $bundle_key])) {
|
674
|
$table = $this->base_table;
|
675
|
}
|
676
|
else {
|
677
|
foreach ($fields as $field_name => $value) {
|
678
|
if ($pos = strpos($field_name, '.' . $bundle_key)) {
|
679
|
$table = substr($field_name, 0, $pos);
|
680
|
break;
|
681
|
}
|
682
|
}
|
683
|
}
|
684
|
$table_data = views_fetch_data($table);
|
685
|
|
686
|
|
687
|
$handler = $table_data[$bundle_key]['filter']['handler'];
|
688
|
if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) {
|
689
|
$value = drupal_map_assoc(array($form_state['values']['show']['type']));
|
690
|
}
|
691
|
else {
|
692
|
$value = $form_state['values']['show']['type'];
|
693
|
}
|
694
|
|
695
|
$filters[$bundle_key] = array(
|
696
|
'id' => $bundle_key,
|
697
|
'table' => $table,
|
698
|
'field' => $bundle_key,
|
699
|
'value' => $value,
|
700
|
);
|
701
|
}
|
702
|
|
703
|
|
704
|
if (!empty($form_state['values']['show']['tagged_with']['tids'])) {
|
705
|
$filters['tid'] = array(
|
706
|
'id' => 'tid',
|
707
|
'table' => 'taxonomy_index',
|
708
|
'field' => 'tid',
|
709
|
'value' => $form_state['values']['show']['tagged_with']['tids'],
|
710
|
'vocabulary' => $form_state['values']['show']['tagged_with']['vocabulary'],
|
711
|
);
|
712
|
|
713
|
|
714
|
if (count($form_state['values']['show']['tagged_with']['tids']) > 1) {
|
715
|
$filters['tid']['operator'] = 'and';
|
716
|
|
717
|
|
718
|
sort($filters['tid']['value']);
|
719
|
}
|
720
|
}
|
721
|
|
722
|
return $filters;
|
723
|
}
|
724
|
|
725
|
protected function default_display_sorts($form, $form_state) {
|
726
|
$sorts = array();
|
727
|
|
728
|
|
729
|
if (isset($this->plugin['sorts'])) {
|
730
|
foreach ($this->plugin['sorts'] as $name => $info) {
|
731
|
$sorts[$name] = $info;
|
732
|
}
|
733
|
}
|
734
|
|
735
|
|
736
|
$sorts = array_merge($sorts, $this->default_display_sorts_user($form, $form_state));
|
737
|
|
738
|
return $sorts;
|
739
|
}
|
740
|
|
741
|
protected function default_display_sorts_user($form, $form_state) {
|
742
|
$sorts = array();
|
743
|
|
744
|
|
745
|
if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') {
|
746
|
list($column, $sort) = explode(':', $form_state['values']['show']['sort']);
|
747
|
|
748
|
$column = explode('-', $column);
|
749
|
if (count($column) > 1) {
|
750
|
$table = $column[0];
|
751
|
$column = $column[1];
|
752
|
}
|
753
|
else {
|
754
|
$table = $this->base_table;
|
755
|
$column = $column[0];
|
756
|
}
|
757
|
|
758
|
$sorts[$column] = array(
|
759
|
'id' => $column,
|
760
|
'table' => $table,
|
761
|
'field' => $column,
|
762
|
'order' => $sort,
|
763
|
);
|
764
|
}
|
765
|
|
766
|
return $sorts;
|
767
|
}
|
768
|
|
769
|
protected function page_display_options($form, $form_state) {
|
770
|
$display_options = array();
|
771
|
$page = $form_state['values']['page'];
|
772
|
$display_options['title'] = $page['title'];
|
773
|
$display_options['path'] = $page['path'];
|
774
|
$display_options['style_plugin'] = $page['style']['style_plugin'];
|
775
|
|
776
|
$display_options['row_plugin'] = isset($page['style']['row_plugin']) ? $page['style']['row_plugin'] : 'fields';
|
777
|
if (empty($page['items_per_page'])) {
|
778
|
$display_options['pager']['type'] = 'none';
|
779
|
}
|
780
|
elseif ($page['pager']) {
|
781
|
$display_options['pager']['type'] = 'full';
|
782
|
}
|
783
|
else {
|
784
|
$display_options['pager']['type'] = 'some';
|
785
|
}
|
786
|
$display_options['pager']['options']['items_per_page'] = $page['items_per_page'];
|
787
|
if (!empty($page['link'])) {
|
788
|
$display_options['menu']['type'] = 'normal';
|
789
|
$display_options['menu']['title'] = $page['link_properties']['title'];
|
790
|
$display_options['menu']['name'] = $page['link_properties']['menu_name'];
|
791
|
}
|
792
|
return $display_options;
|
793
|
}
|
794
|
|
795
|
protected function block_display_options($form, $form_state) {
|
796
|
$display_options = array();
|
797
|
$block = $form_state['values']['block'];
|
798
|
$display_options['title'] = $block['title'];
|
799
|
$display_options['style_plugin'] = $block['style']['style_plugin'];
|
800
|
$display_options['row_plugin'] = isset($block['style']['row_plugin']) ? $block['style']['row_plugin'] : 'fields';
|
801
|
$display_options['pager']['type'] = $block['pager'] ? 'full' : (empty($block['items_per_page']) ? 'none' : 'some');
|
802
|
$display_options['pager']['options']['items_per_page'] = $block['items_per_page'];
|
803
|
return $display_options;
|
804
|
}
|
805
|
|
806
|
protected function page_feed_display_options($form, $form_state) {
|
807
|
$display_options = array();
|
808
|
$display_options['pager']['type'] = 'some';
|
809
|
$display_options['style_plugin'] = 'rss';
|
810
|
$display_options['row_plugin'] = $form_state['values']['page']['feed_properties']['row_plugin'];
|
811
|
$display_options['path'] = $form_state['values']['page']['feed_properties']['path'];
|
812
|
$display_options['title'] = $form_state['values']['page']['title'];
|
813
|
$display_options['displays'] = array(
|
814
|
'default' => 'default',
|
815
|
'page' => 'page',
|
816
|
);
|
817
|
return $display_options;
|
818
|
}
|
819
|
|
820
|
|
821
|
|
822
|
|
823
|
|
824
|
|
825
|
|
826
|
|
827
|
|
828
|
|
829
|
|
830
|
|
831
|
|
832
|
|
833
|
|
834
|
|
835
|
|
836
|
|
837
|
|
838
|
|
839
|
protected function set_default_options($options, $display, $default_display) {
|
840
|
foreach ($options as $option => $value) {
|
841
|
|
842
|
|
843
|
$default_value = $default_display->get_option($option);
|
844
|
if (isset($default_value)) {
|
845
|
$default_display->set_option($option, $value);
|
846
|
}
|
847
|
else {
|
848
|
$display->set_option($option, $value);
|
849
|
}
|
850
|
}
|
851
|
}
|
852
|
|
853
|
|
854
|
|
855
|
|
856
|
|
857
|
|
858
|
|
859
|
|
860
|
|
861
|
|
862
|
|
863
|
|
864
|
|
865
|
|
866
|
|
867
|
|
868
|
|
869
|
|
870
|
|
871
|
|
872
|
|
873
|
|
874
|
|
875
|
protected function set_override_options($options, $display, $default_display) {
|
876
|
foreach ($options as $option => $value) {
|
877
|
|
878
|
|
879
|
$default_value = $default_display->get_option($option);
|
880
|
if (!isset($default_value)) {
|
881
|
$display->set_option($option, $value);
|
882
|
}
|
883
|
elseif ($default_value !== $value) {
|
884
|
$display->override_option($option, $value);
|
885
|
}
|
886
|
}
|
887
|
}
|
888
|
|
889
|
protected function retrieve_validated_view($form, $form_state, $unset = TRUE) {
|
890
|
$key = hash('sha256', serialize($form_state['values']));
|
891
|
$view = (isset($this->validated_views[$key]) ? $this->validated_views[$key] : NULL);
|
892
|
if ($unset) {
|
893
|
unset($this->validated_views[$key]);
|
894
|
}
|
895
|
return $view;
|
896
|
}
|
897
|
|
898
|
protected function set_validated_view($form, $form_state, $view) {
|
899
|
$key = hash('sha256', serialize($form_state['values']));
|
900
|
$this->validated_views[$key] = $view;
|
901
|
}
|
902
|
|
903
|
|
904
|
|
905
|
|
906
|
function validate($form, &$form_state) {
|
907
|
$view = $this->instantiate_view($form, $form_state);
|
908
|
$errors = $view->validate();
|
909
|
if (!is_array($errors) || empty($errors)) {
|
910
|
$this->set_validated_view($form, $form_state, $view);
|
911
|
return array();
|
912
|
}
|
913
|
return $errors;
|
914
|
}
|
915
|
|
916
|
|
917
|
|
918
|
|
919
|
|
920
|
|
921
|
function create_view($form, &$form_state) {
|
922
|
$view = $this->retrieve_validated_view($form, $form_state);
|
923
|
if (empty($view)) {
|
924
|
throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated'));
|
925
|
}
|
926
|
return $view;
|
927
|
}
|
928
|
|
929
|
}
|