-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews_slideshow.module
500 lines (463 loc) · 15.9 KB
/
views_slideshow.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<?php
/**
* @file
* Provides Slideshow style options for Views.
*/
/**
* Implements hook_theme().
*/
function views_slideshow_theme() {
return array(
'views_slideshow_main_section' => array(
'variables' => array(
'vss_id' => NULL,
'slides' => NULL,
'plugin' => NULL,
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_main_section__',
),
'views_slideshow_pager_widget_render' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'rows' => array(),
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_pager_widget_render__',
'function' => 'template_preprocess_views_slideshow_pager_widget_render',
),
'views_slideshow_pager_fields' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'attributes' => array(),
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_pager_fields__',
),
'views_slideshow_pager_field_field' => array(
'variables' => array(
'view' => NULL,
'css_identifier' => NULL,
'label' => NULL,
'output' => NULL,
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_pager_field_field__',
),
'views_slideshow_pager_field_item' => array(
'variables' => array(
'vss_id' => NULL,
'item' => NULL,
'count' => NULL,
'location' => NULL,
'length' => NULL,
),
//'pattern' => 'views_slideshow_pager_field_item__',
),
'views_slideshow_controls_widget_render' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'rows' => array(),
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_controls_widget_render__',
'function' => 'template_preprocess_views_slideshow_controls_widget_render',
),
'views_slideshow_controls_text' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'rows' => array(),
),
//'pattern' => 'views_slideshow_controls_text__',
'file' => 'views_slideshow.theme.inc',
),
'views_slideshow_controls_text_previous' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
),
//'pattern' => 'views_slideshow_controls_text_previous__',
'file' => 'views_slideshow.theme.inc',
),
'views_slideshow_controls_text_pause' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
),
//'pattern' => 'views_slideshow_controls_text_pause__',
'file' => 'views_slideshow.theme.inc',
),
'views_slideshow_controls_text_next' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
),
//'pattern' => 'views_slideshow_controls_text_next__',
'file' => 'views_slideshow.theme.inc',
),
'views_slideshow_slide_counter_widget_render' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'rows' => array(),
),
'file' => 'views_slideshow.theme.inc',
//'pattern' => 'views_slideshow_counter_widget_render__',
'function' => 'template_preprocess_views_slideshow_slide_counter_widget_render',
),
'views_slideshow_slide_counter' => array(
'variables' => array(
'vss_id' => NULL,
'view' => NULL,
'settings' => array(),
'location' => NULL,
'rows' => array(),
),
//'pattern' => 'views_slideshow_slide_counter__',
'file' => 'views_slideshow.theme.inc',
),
);
}
/**
* Implements hook_views_slideshow_skin_info().
*/
function views_slideshow_views_slideshow_skin_info() {
return array(
'default' => array(
'name' => t('Default'),
),
);
}
/**
* Implements hook_views_slideshow_widget_info().
*/
function views_slideshow_views_slideshow_widget_info() {
return array(
'views_slideshow_pager' => array(
'name' => t('Pager'),
'accepts' => array(
'transitionBegin' => array('required' => TRUE),
'goToSlide',
'previousSlide',
'nextSlide',
),
'calls' => array(
'goToSlide',
'pause',
'play',
),
),
'views_slideshow_controls' => array(
'name' => t('Controls'),
'accepts' => array(
'pause' => array('required' => TRUE),
'play' => array('required' => TRUE),
),
'calls' => array(
'nextSlide',
'pause',
'play',
'previousSlide',
),
),
'views_slideshow_slide_counter' => array(
'name' => t('Slide Counter'),
'accepts' => array(
'transitionBegin' => array('required' => TRUE),
'goToSlide',
'previousSlide',
'nextSlide',
),
'calls' => array(),
),
);
}
/**
* Implements [widget]_views_slideshow_widget_form_options().
*/
function views_slideshow_pager_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
// Get all the pager info from other modules.
$pagers = \Drupal::moduleHandler()->invokeAll('views_slideshow_widget_pager_info', array($view));
if (!empty($pagers)) {
$pager_options = array();
foreach ($pagers as $pager_id => $pager_info) {
$pager_options[$pager_id] = $pager_info['name'];
}
asort($pager_options);
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_wrapper'] = array(
'#markup' => '<div class="vs-dependent">',
);
// Add field to see if they would like to hide pager if there is only one
// slide.
$form['hide_on_single_slide'] = array(
'#type' => 'checkbox',
'#title' => t('Hide pager if there is only one slide'),
'#default_value' => $defaults['hide_on_single_slide'],
'#description' => t('Should the pager be hidden if there is only one slide.'),
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
),
),
);
// Create the widget type field.
$form['type'] = array(
'#type' => 'select',
'#title' => t('Pager Type'),
'#description' => t('Style of the pager'),
'#default_value' => $defaults['type'],
'#options' => $pager_options,
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
),
),
);
// Add any additional form elements.
// Build our arguments to pass to
// [pager-type]_views_slideshow_widget_pager_form_options().
$arguments = array(
&$form,
&$form_state,
&$view,
$defaults,
$dependency,
);
foreach ($pagers as $pager_key => $pager_info) {
$function = $pager_key . '_views_slideshow_widget_pager_form_options';
if (function_exists($function)) {
call_user_func_array($function, $arguments);
}
}
$form['views_slideshow_pager_wrapper_close'] = array(
'#markup' => '</div>',
);
}
else {
$form['enable_pager'] = array(
'#markup' => 'There are no pagers available.',
);
}
}
/**
* Implements [widget-type]_views_slideshow_pager_form_options().
*/
function views_slideshow_pager_fields_views_slideshow_widget_pager_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
// Settings for fields pager.
$options = array();
// Get each field and it's name.
foreach ($view->displayHandler->getHandlers('field') as $field => $handler) {
$options[$field] = $handler->adminLabel();
}
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_fields_wrapper'] = array(
'#markup' => '<div class="vs-dependent">',
);
// Add ability to choose which fields to show in the pager.
$form['views_slideshow_pager_fields_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Pager fields'),
'#options' => $options,
'#default_value' => $defaults['views_slideshow_pager_fields_fields'],
'#description' => t('Choose the fields that will appear in the pager.'),
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
),
),
);
// Add field to see if they would like to activate slide and pause on pager
// hover.
$form['views_slideshow_pager_fields_hover'] = array(
'#type' => 'checkbox',
'#title' => t('Activate Slide and Pause on Pager Hover'),
'#default_value' => $defaults['views_slideshow_pager_fields_hover'],
'#description' => t('Should the slide be activated and paused when hovering over a pager item.'),
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
),
),
);
$form['views_slideshow_pager_fields_wrapper_close'] = array(
'#markup' => '</div>',
);
}
/**
* Implements [widget]_views_slideshow_widget_form_options().
*/
function views_slideshow_controls_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
// Get all the control info from other modules.
$controls = \Drupal::moduleHandler()->invokeAll('views_slideshow_widget_controls_info', array($view));
if (!empty($controls)) {
$control_type_options = array();
foreach ($controls as $control_id => $control_info) {
$control_type_options[$control_id] = $control_info['name'];
}
asort($control_type_options);
// Need to wrap this so it indents correctly.
$form['views_slideshow_controls_wrapper'] = array(
'#markup' => '<div class="vs-dependent">',
);
// Add field to see if they would like to hide controls if there is only one
// slide.
$form['hide_on_single_slide'] = array(
'#type' => 'checkbox',
'#title' => t('Hide controls if there is only one slide'),
'#default_value' => $defaults['hide_on_single_slide'],
'#description' => t('Should the controls be hidden if there is only one slide.'),
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
),
),
);
// Create the widget type field.
$form['type'] = array(
'#type' => 'select',
'#title' => t('Controls Type'),
'#description' => t('Style of the controls'),
'#default_value' => $defaults['type'],
'#options' => $control_type_options,
'#states' => array(
'visible' => array(
':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
),
),
);
// Add any additional form elements
// Build our arguments to pass to
// [pager-type]_views_slideshow_widget_pager_form_options
$arguments = array(
&$form,
&$form_state,
&$view,
$defaults,
$dependency,
);
foreach ($controls as $control_key => $control_info) {
$function = $control_key . '_views_slideshow_widget_controls_form_options';
if (function_exists($function)) {
call_user_func_array($function, $arguments);
}
}
$form['controls_wrapper_close'] = array(
'#markup' => '</div>',
);
}
else {
$form['enable_controls'] = array(
'#markup' => 'There are no controls available.',
);
}
}
/**
* Implements hook_views_slideshow_widget_pager_info().
*/
function views_slideshow_views_slideshow_widget_pager_info($view) {
$settings = array();
// Settings for fields pager.
// First verify that the view is using fields.
if ($view->usesFields()) {
$settings = array(
'views_slideshow_pager_fields' => array(
'name' => t('Fields'),
),
);
}
return $settings;
}
/**
* Implements hook_views_slideshow_controls_info().
*/
function views_slideshow_views_slideshow_widget_controls_info($view) {
return array(
'views_slideshow_controls_text' => array(
'name' => t('Text'),
),
);
}
/**
* Implements hook_views_slideshow_option_definition().
*/
function views_slideshow_views_slideshow_option_definition() {
// Default slideshow type and skins.
$options['slideshow_type'] = array('default' => '');
$options['slideshow_skin'] = array('default' => '');
$options['skin_info'] = array(
'default' => array(
'class' => 'default',
'name' => t('Untitled skin'),
'module' => 'views_slideshow',
'libraries' => array(),
),
);
// Set default widgets and weight values.
$widgets = \Drupal::moduleHandler()->invokeAll('views_slideshow_widget_info');
if ($widgets) {
$locations = array('top', 'bottom');
foreach ($locations as $location) {
foreach ($widgets as $widget_id => $widget_name) {
$options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['enable'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['weight'] = array('default' => 1);
// Defaults for the pager widget.
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['hide_on_single_slide'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['type'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_hover'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_click_to_page'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_hover'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_click_to_page'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_fields'] = array('default' => array());
$options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_hover'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['hide_on_single_slide'] = array('default' => 0);
$options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['type'] = array('default' => 0);
}
}
}
return $options;
}
/**
* Preg_replace_callback callback().
*
* @see views_slideshow_format_addons_name()
*/
function _views_slideshow_get_preg_strtoupper_callback($matches) {
if (isset($matches[1])) {
return strtoupper($matches[1]);
}
}
/**
* Php5.x preg_replace_callback() method.
*/
function views_slideshow_format_addons_name($subject) {
return preg_replace_callback('/_(.?)/', '_views_slideshow_get_preg_strtoupper_callback', $subject);
}
/**
* Views Slideshow: Slideshow.
*
* As it is a preprocess function, store it with other functions in theme.inc.
*/
function template_preprocess_views_view_slideshow(&$vars) {
\Drupal::moduleHandler()->loadInclude('views_slideshow', 'inc', 'views_slideshow.theme');
_views_slideshow_preprocess_views_view_slideshow($vars);
}