Révision a60304ed
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/flexslider/flexslider_fields/flexslider_fields.module | ||
---|---|---|
15 | 15 |
* of an image field. |
16 | 16 |
*/ |
17 | 17 |
function flexslider_fields_field_formatter_info() { |
18 |
return array(
|
|
18 |
$info = array(
|
|
19 | 19 |
'flexslider' => array( |
20 | 20 |
'label' => t('flexslider'), |
21 | 21 |
'field types' => array('image', 'media'), |
... | ... | |
26 | 26 |
), |
27 | 27 |
), |
28 | 28 |
); |
29 |
// Integrate with file entity / media. |
|
30 |
if (module_exists('file_entity')) { |
|
31 |
$info['flexslider_file_entity'] = array( |
|
32 |
'label' => t('FlexSlider File Entity'), |
|
33 |
'description' => t('Render files in a specific view mode.'), |
|
34 |
'field types' => array('image', 'media', 'file'), |
|
35 |
'settings' => array( |
|
36 |
'optionset' => 'default', |
|
37 |
'file_view_mode' => 'default', |
|
38 |
'caption' => FALSE, |
|
39 |
), |
|
40 |
); |
|
41 |
} |
|
42 |
return $info; |
|
29 | 43 |
} |
30 | 44 |
|
31 | 45 |
/** |
... | ... | |
54 | 68 |
'#default_value' => $settings['optionset'], |
55 | 69 |
); |
56 | 70 |
|
57 |
$image_styles = image_style_options(FALSE, PASS_THROUGH); |
|
58 |
$form['image_style'] = array( |
|
71 |
if ($display['type'] == 'flexslider') { |
|
72 |
$image_styles = image_style_options(FALSE, PASS_THROUGH); |
|
73 |
$form['image_style'] = array( |
|
59 | 74 |
'#title' => t('Image style'), |
60 | 75 |
'#type' => 'select', |
61 | 76 |
'#default_value' => $settings['image_style'], |
62 | 77 |
'#empty_option' => t('None (original image)'), |
63 | 78 |
'#options' => $image_styles, |
64 |
); |
|
79 |
); |
|
80 |
} |
|
81 |
elseif ($display['type'] == 'flexslider_file_entity') { |
|
82 |
$form['file_view_mode'] = array( |
|
83 |
'#title' => t('File view mode'), |
|
84 |
'#type' => 'select', |
|
85 |
'#default_value' => $settings['file_view_mode'], |
|
86 |
'#options' => file_entity_view_mode_labels(), |
|
87 |
); |
|
88 |
} |
|
65 | 89 |
|
66 | 90 |
if (!empty($instance['settings'])) { |
67 | 91 |
// If the image field doesn't have the Title field enabled, tell the user. |
68 | 92 |
if ($instance['settings']['title_field'] == FALSE and $instance['bundle'] != 'ctools') { |
69 | 93 |
$form['caption'] = array( |
70 |
'#title' => t('Use image title as the caption'),
|
|
71 |
'#type' => 'checkbox',
|
|
94 |
'#title' => t('Choose a caption source'),
|
|
95 |
'#type' => 'select',
|
|
72 | 96 |
'#disabled' => TRUE, |
97 |
'#options' => array( |
|
98 |
0 => t('None'), |
|
99 |
1 => t('Image title'), |
|
100 |
'alt' => t('Image ALT attribute'), |
|
101 |
), |
|
73 | 102 |
'#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 | 103 |
); |
75 | 104 |
} |
76 | 105 |
else { |
77 | 106 |
$form['caption'] = array( |
78 |
'#title' => t('Use image title as the caption'), |
|
79 |
'#type' => 'checkbox', |
|
107 |
'#title' => t('Choose a caption source'), |
|
108 |
'#type' => 'select', |
|
109 |
'#options' => array( |
|
110 |
0 => t('None'), |
|
111 |
1 => t('Image title'), |
|
112 |
'alt' => t('Image ALT attribute'), |
|
113 |
), |
|
80 | 114 |
'#default_value' => $settings['caption'], |
81 | 115 |
); |
82 | 116 |
} |
... | ... | |
96 | 130 |
|
97 | 131 |
$summary = array(); |
98 | 132 |
|
99 |
// Load option set |
|
133 |
// Load option set.
|
|
100 | 134 |
ctools_include('export'); |
101 | 135 |
if (!empty($settings['optionset'])) { |
102 | 136 |
$o = flexslider_optionset_load($settings['optionset']); |
... | ... | |
105 | 139 |
} |
106 | 140 |
} |
107 | 141 |
|
108 |
// Display the selected image style |
|
109 |
if (!empty($settings['image_style'])) { |
|
110 |
$is = t('Image style: %imagestyle', array('%imagestyle' => $settings['image_style'])); |
|
142 |
// Display the selected image style. |
|
143 |
if ($instance['display'][$view_mode]['type'] == 'flexslider') { |
|
144 |
if (!empty($settings['image_style'])) { |
|
145 |
$is = t('Image style: %imagestyle', array('%imagestyle' => $settings['image_style'])); |
|
146 |
} |
|
147 |
else { |
|
148 |
$is = t('Image style: None (original image)'); |
|
149 |
} |
|
111 | 150 |
} |
112 |
else { |
|
113 |
$is = t('Image style: None (original image)'); |
|
151 |
elseif ($instance['display'][$view_mode]['type'] == 'flexslider_file_entity') { |
|
152 |
if (!empty($settings['file_view_mode'])) { |
|
153 |
$is = t('File view mode: %file_view_mode', array( |
|
154 |
'%file_view_mode' => file_entity_view_mode_label($settings['file_view_mode']), |
|
155 |
)); |
|
156 |
} |
|
157 |
else { |
|
158 |
$is = t('File view mode: Default'); |
|
159 |
} |
|
114 | 160 |
} |
115 | 161 |
|
116 |
// Build settings summary |
|
162 |
// Build settings summary.
|
|
117 | 163 |
$optionset = isset($optionset) ? $optionset->title : t('Default settings'); |
118 | 164 |
$summary[] = t('Option set: %optionset', array('%optionset' => $optionset)); |
119 | 165 |
$summary[] = $is; |
... | ... | |
124 | 170 |
/** |
125 | 171 |
* Implements hook_field_formatter_view(). |
126 | 172 |
* |
127 |
* Prepares a renderable array of images and adds the neccessary JS and CSS
|
|
173 |
* Prepares a renderable array of images and adds the necessary JS and CSS.
|
|
128 | 174 |
*/ |
129 | 175 |
function flexslider_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { |
130 | 176 |
|
177 |
// If file entity formatter is selected render all files initially. |
|
178 |
if ($display['type'] == 'flexslider_file_entity') { |
|
179 |
$file_display = $display; |
|
180 |
$file_display['type'] = 'file_rendered'; |
|
181 |
$file_items = module_invoke('file_entity', 'field_formatter_view', $entity_type, $entity, $field, $instance, $langcode, $items, $file_display); |
|
182 |
} |
|
183 |
|
|
131 | 184 |
$element = array(); |
132 | 185 |
if (count($items) > 0) { |
133 | 186 |
|
... | ... | |
157 | 210 |
$item['slide']['title'] = $item['item']['title']; |
158 | 211 |
} |
159 | 212 |
|
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']); |
|
213 |
// Render the slide item. |
|
214 |
if ($display['type'] == 'flexslider') { |
|
215 |
// If no style set, we have to call theme_image since theme_image_style |
|
216 |
// doesn't auto-fallback to full size image. |
|
217 |
if (!empty($item['slide']['style_name'])) { |
|
218 |
// Generate the HTML for the slide. |
|
219 |
$item['slide'] = theme('image_style', $item['slide']); |
|
220 |
} |
|
221 |
else { |
|
222 |
// Generate the HTML for the slide. |
|
223 |
$item['slide'] = theme('image', $item['slide']); |
|
224 |
} |
|
166 | 225 |
} |
167 |
else { |
|
168 |
// Generate the HTML for the slide |
|
169 |
$item['slide'] = theme('image', $item['slide']); |
|
226 |
elseif ($display['type'] == 'flexslider_file_entity') { |
|
227 |
$item['slide'] = render($file_items[$key]); |
|
170 | 228 |
} |
171 | 229 |
|
172 |
// Check caption settings |
|
173 |
if ($display['settings']['caption']) { |
|
230 |
// Check caption settings.
|
|
231 |
if ($display['settings']['caption'] === '1') {
|
|
174 | 232 |
$item['caption'] = filter_xss($item['item']['title']); |
175 | 233 |
} |
234 |
elseif ($display['settings']['caption'] === 'alt') { |
|
235 |
$item['caption'] = filter_xss($item['item']['alt']); |
|
236 |
} |
|
176 | 237 |
|
177 | 238 |
$items[$key] = $item; |
178 | 239 |
} |
179 | 240 |
|
180 |
$element = array( |
|
241 |
$element[0] = array(
|
|
181 | 242 |
'#theme' => 'flexslider', |
182 | 243 |
'#items' => $items, |
183 | 244 |
'#settings' => $display['settings'], |
... | ... | |
185 | 246 |
} |
186 | 247 |
|
187 | 248 |
return $element; |
188 |
} |
|
249 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules