1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* flexslider style plugin for the Views module.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Implements a style type plugin for the Views module.
|
9 |
|
|
*/
|
10 |
|
|
class flexslider_views_plugin_style_flexslider extends views_plugin_style {
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Set default options.
|
14 |
|
|
*/
|
15 |
|
|
function option_definition() {
|
16 |
|
|
$options = parent::option_definition();
|
17 |
|
|
$options += array(
|
18 |
|
|
'optionset' => array('default' => 'default'),
|
19 |
|
|
'captionfield' => array('default' => ''),
|
20 |
|
|
'id' => array('default' => ''),
|
21 |
|
|
);
|
22 |
|
|
|
23 |
|
|
return $options;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Show a form to edit the style options.
|
28 |
|
|
*/
|
29 |
|
|
function options_form(&$form, &$form_state) {
|
30 |
|
|
parent::options_form($form, $form_state);
|
31 |
|
|
|
32 |
|
|
$form['flexslider'] = array(
|
33 |
|
|
'#type' => 'fieldset',
|
34 |
|
|
'#title' => t('FlexSlider'),
|
35 |
|
|
);
|
36 |
|
|
|
37 |
|
|
$optionsets = array();
|
38 |
|
|
foreach (flexslider_optionset_load_all() as $name => $optionset) {
|
39 |
|
|
$optionsets[$name] = check_plain($optionset->title);
|
40 |
|
|
}
|
41 |
|
|
$form['flexslider']['optionset'] = array(
|
42 |
|
|
'#title' => t('Option set'),
|
43 |
|
|
'#type' => 'select',
|
44 |
|
|
'#options' => $optionsets,
|
45 |
|
|
'#default_value' => $this->options['optionset'],
|
46 |
|
|
);
|
47 |
|
|
|
48 |
|
|
$link_options = array('' => t('None'));
|
49 |
|
|
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
50 |
|
|
$link_options[$field] = $handler->ui_name();
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
$captionfield_options = array('' => t('None'));
|
54 |
|
|
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
55 |
|
|
$captionfield_options[$field] = $handler->ui_name();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
$form['flexslider']['captionfield'] = array(
|
59 |
|
|
'#type' => 'select',
|
60 |
|
|
'#title' => t('Caption Field'),
|
61 |
|
|
'#description' => t("Select a field to be used as the caption. This can also be set manually by adding the '.flex-caption' class to a field. Required to use thumbnail captions."),
|
62 |
|
|
'#options' => $captionfield_options,
|
63 |
|
|
'#default_value' => $this->options['captionfield'],
|
64 |
|
|
);
|
65 |
|
|
|
66 |
|
|
$form['flexslider']['id'] = array(
|
67 |
|
|
'#type' => 'textfield',
|
68 |
|
|
'#title' => t('Element ID'),
|
69 |
|
|
'#description' => t("Manually define the FlexSlider container ID attribute <em>Ensure you don't display similar ID elements on the same page</em>."),
|
70 |
|
|
'#size' => 40,
|
71 |
|
|
'#maxlength' => 255,
|
72 |
|
|
'#default_value' => $this->options['id'],
|
73 |
|
|
);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Performs some cleanup tasks on the options array before saving it.
|
78 |
|
|
*/
|
79 |
|
|
function options_submit(&$form, &$form_state) {
|
80 |
|
|
$options =& $form_state['values']['style_options'];
|
81 |
|
|
|
82 |
|
|
// In some cases, namely when the style settings are overriden for this display,
|
83 |
|
|
// the flexslider options aren't in a sub array. No idea why. But this
|
84 |
|
|
// prevents a fatal error.
|
85 |
|
|
if (!empty($options['flexslider'])) {
|
86 |
|
|
// Pull the fieldset values one level up
|
87 |
|
|
$options += $options['flexslider'];
|
88 |
|
|
unset($options['flexslider']);
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
/**
|
93 |
|
|
* Render the display in this style.
|
94 |
|
|
*/
|
95 |
|
|
function render() {
|
96 |
|
|
|
97 |
|
|
// Group the rows according to the grouping field, if specified.
|
98 |
|
|
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);
|
99 |
|
|
|
100 |
|
|
// Render each group separately and concatenate.
|
101 |
|
|
$output = '';
|
102 |
|
|
|
103 |
|
|
foreach ($sets as $title => $rows) {
|
104 |
|
|
// Add caption field if chosen.
|
105 |
|
|
if (!empty($this->options['captionfield'])) {
|
106 |
|
|
$caption_field = $this->options['captionfield'];
|
107 |
|
|
foreach ($rows as $index => $row) {
|
108 |
|
|
$rows[$index]->caption = $this->rendered_fields[$index][$caption_field];
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
$output .= theme($this->theme_functions(),
|
112 |
|
|
array(
|
113 |
|
|
'view' => $this->view,
|
114 |
|
|
'options' => $this->options,
|
115 |
|
|
'rows' => $rows,
|
116 |
|
|
'title' => $title
|
117 |
|
|
)
|
118 |
|
|
);
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
return $output;
|
122 |
|
|
}
|
123 |
|
|
} |