1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Adds fields integration with FlexSlider
|
6 |
|
|
*
|
7 |
|
|
* @author jepedo
|
8 |
|
|
* @author Mathew Winstone <mwinstone@coldfrontlabs.ca>
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
|
|
/**
|
12 |
|
|
* Implements hook_field_formatter_info().
|
13 |
|
|
*
|
14 |
|
|
* Adds the flexslider format option within the manage display form of
|
15 |
|
|
* of an image field.
|
16 |
|
|
*/
|
17 |
|
|
function flexslider_fields_field_formatter_info() {
|
18 |
|
|
return array(
|
19 |
|
|
'flexslider' => array(
|
20 |
|
|
'label' => t('flexslider'),
|
21 |
|
|
'field types' => array('image', 'media'),
|
22 |
|
|
'settings' => array(
|
23 |
|
|
'optionset' => 'default',
|
24 |
|
|
'image_style' => '',
|
25 |
|
|
'caption' => FALSE,
|
26 |
|
|
),
|
27 |
|
|
),
|
28 |
|
|
);
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* Implements hook_field_formatter_settings_form().
|
33 |
|
|
*
|
34 |
|
|
* Provides display settings form within the manage display page of
|
35 |
|
|
* an image field with formatter flexslider.
|
36 |
|
|
*/
|
37 |
|
|
function flexslider_fields_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
38 |
|
|
$display = $instance['display'][$view_mode];
|
39 |
|
|
$settings = $display['settings'];
|
40 |
|
|
|
41 |
|
|
$form = array();
|
42 |
|
|
|
43 |
|
|
// Show select box for the option set
|
44 |
|
|
$optionsets = array();
|
45 |
|
|
ctools_include('export');
|
46 |
|
|
foreach (flexslider_optionset_load_all() as $name => $optionset) {
|
47 |
|
|
$optionsets[$name] = check_plain($optionset->title);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
$form['optionset'] = array(
|
51 |
|
|
'#title' => t('Option set'),
|
52 |
|
|
'#type' => 'select',
|
53 |
|
|
'#options' => $optionsets,
|
54 |
|
|
'#default_value' => $settings['optionset'],
|
55 |
|
|
);
|
56 |
|
|
|
57 |
|
|
$image_styles = image_style_options(FALSE, PASS_THROUGH);
|
58 |
|
|
$form['image_style'] = array(
|
59 |
|
|
'#title' => t('Image style'),
|
60 |
|
|
'#type' => 'select',
|
61 |
|
|
'#default_value' => $settings['image_style'],
|
62 |
|
|
'#empty_option' => t('None (original image)'),
|
63 |
|
|
'#options' => $image_styles,
|
64 |
|
|
);
|
65 |
|
|
|
66 |
955823d8
|
Assos Assos
|
if (!empty($instance['settings'])) {
|
67 |
|
|
// If the image field doesn't have the Title field enabled, tell the user.
|
68 |
|
|
if ($instance['settings']['title_field'] == FALSE and $instance['bundle'] != 'ctools') {
|
69 |
|
|
$form['caption'] = array(
|
70 |
|
|
'#title' => t('Use image title as the caption'),
|
71 |
|
|
'#type' => 'checkbox',
|
72 |
|
|
'#disabled' => TRUE,
|
73 |
|
|
'#description' => t('You need to <a href="@url">enable the Title field</a> for this image field to be able use it as a caption.', array('@url' => url('admin/structure/types/manage/' . $instance['bundle'] . '/fields/' . $instance['field_name'], array('fragment' => 'edit-instance-settings-title-field', 'query' => array('destination' => 'admin/structure/types/manage/' . $instance['bundle'] . '/display'))))),
|
74 |
|
|
);
|
75 |
|
|
}
|
76 |
|
|
else {
|
77 |
|
|
$form['caption'] = array(
|
78 |
|
|
'#title' => t('Use image title as the caption'),
|
79 |
|
|
'#type' => 'checkbox',
|
80 |
|
|
'#default_value' => $settings['caption'],
|
81 |
|
|
);
|
82 |
|
|
}
|
83 |
85ad3d82
|
Assos Assos
|
}
|
84 |
|
|
|
85 |
|
|
return $form;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Implements hook_field_formatter_settings_summary().
|
90 |
|
|
*
|
91 |
|
|
* Displays the summary of the set options of a flexslider formatted image field
|
92 |
|
|
*/
|
93 |
|
|
function flexslider_fields_field_formatter_settings_summary($field, $instance, $view_mode) {
|
94 |
|
|
$display = $instance['display'][$view_mode];
|
95 |
|
|
$settings = $display['settings'];
|
96 |
|
|
|
97 |
|
|
$summary = array();
|
98 |
|
|
|
99 |
|
|
// Load option set
|
100 |
|
|
ctools_include('export');
|
101 |
|
|
if (!empty($settings['optionset'])) {
|
102 |
|
|
$o = flexslider_optionset_load($settings['optionset']);
|
103 |
|
|
if ($o !== NULL) {
|
104 |
|
|
$optionset = $o;
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
// Display the selected image style
|
109 |
|
|
if (!empty($settings['image_style'])) {
|
110 |
|
|
$is = t('Image style: %imagestyle', array('%imagestyle' => $settings['image_style']));
|
111 |
|
|
}
|
112 |
|
|
else {
|
113 |
|
|
$is = t('Image style: None (original image)');
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
// Build settings summary
|
117 |
|
|
$optionset = isset($optionset) ? $optionset->title : t('Default settings');
|
118 |
|
|
$summary[] = t('Option set: %optionset', array('%optionset' => $optionset));
|
119 |
|
|
$summary[] = $is;
|
120 |
|
|
|
121 |
|
|
return implode('<br />', $summary);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
/**
|
125 |
|
|
* Implements hook_field_formatter_view().
|
126 |
|
|
*
|
127 |
|
|
* Prepares a renderable array of images and adds the neccessary JS and CSS
|
128 |
|
|
*/
|
129 |
|
|
function flexslider_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
130 |
|
|
|
131 |
|
|
$element = array();
|
132 |
|
|
if (count($items) > 0) {
|
133 |
|
|
|
134 |
|
|
foreach ($items as $key => $item) {
|
135 |
955823d8
|
Assos Assos
|
if(isset($item['item'])) continue;
|
136 |
85ad3d82
|
Assos Assos
|
$tmp = $item;
|
137 |
|
|
$item = array();
|
138 |
|
|
$item['item'] = $tmp;
|
139 |
|
|
|
140 |
|
|
// Setup the variables for calling theme_image_style
|
141 |
955823d8
|
Assos Assos
|
if (isset($item['item']['uri'])) {
|
142 |
|
|
$item['slide']['path'] = $item['item']['uri'];
|
143 |
|
|
}
|
144 |
|
|
if (isset($display['settings']['image_style'])) {
|
145 |
|
|
$item['slide']['style_name'] = $display['settings']['image_style'];
|
146 |
|
|
}
|
147 |
|
|
if (isset($item['item']['width'])) {
|
148 |
|
|
$item['slide']['width'] = $item['item']['width'];
|
149 |
|
|
}
|
150 |
|
|
if (isset($item['item']['height'])) {
|
151 |
|
|
$item['slide']['height'] = $item['item']['height'];
|
152 |
|
|
}
|
153 |
|
|
if (isset($item['item']['alt'])) {
|
154 |
|
|
$item['slide']['alt'] = $item['item']['alt'];
|
155 |
|
|
}
|
156 |
|
|
if (isset($item['item']['title'])) {
|
157 |
|
|
$item['slide']['title'] = $item['item']['title'];
|
158 |
|
|
}
|
159 |
85ad3d82
|
Assos Assos
|
|
160 |
|
|
// Render the slide item
|
161 |
|
|
// If not style set, we have to call theme_image since theme_image_style
|
162 |
|
|
// doesn't auto-fallback to full size image
|
163 |
|
|
if (!empty($item['slide']['style_name'])) {
|
164 |
|
|
// Generate the HTML for the slide
|
165 |
|
|
$item['slide'] = theme('image_style', $item['slide']);
|
166 |
|
|
}
|
167 |
|
|
else {
|
168 |
|
|
// Generate the HTML for the slide
|
169 |
|
|
$item['slide'] = theme('image', $item['slide']);
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
// Check caption settings
|
173 |
|
|
if ($display['settings']['caption']) {
|
174 |
|
|
$item['caption'] = filter_xss($item['item']['title']);
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
$items[$key] = $item;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
$element = array(
|
181 |
|
|
'#theme' => 'flexslider',
|
182 |
|
|
'#items' => $items,
|
183 |
|
|
'#settings' => $display['settings'],
|
184 |
|
|
);
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
return $element;
|
188 |
|
|
} |