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