Révision 05237dd8
Ajouté par Assos Assos il y a presque 7 ans
drupal7/sites/all/themes/bootstrap/includes/alter.inc | ||
---|---|---|
199 | 199 |
return $info; |
200 | 200 |
} |
201 | 201 |
|
202 |
/** |
|
203 |
* Implements hook_field_widget_form_alter(). |
|
204 |
*/ |
|
205 |
function bootstrap_field_widget_form_alter(&$element, &$form_state, $context) { |
|
206 |
$widget_type = isset($context['instance']['widget']['type']) ? $context['instance']['widget']['type'] : NULL; |
|
207 |
if ($widget_type === 'image_image') { |
|
208 |
foreach (element_children($element) as $child) { |
|
209 |
$element[$child]['#process'][] = '_bootstrap_image_field_widget_process'; |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Implements above #process callback. |
|
216 |
*/ |
|
217 |
function _bootstrap_image_field_widget_process($element, &$form_state, $form) { |
|
218 |
// Core explicitly sets #theme_wrappers to an empty array for the upload |
|
219 |
// element (perhaps for styling reasons?). Thus, bootstrap_form_element() is |
|
220 |
// invoked, preventing any necessary logic from executing. To achieve the |
|
221 |
// same goal and keep backwards compatibility, reset the theme wrapper back |
|
222 |
// and indicating that the wrapper shouldn't be printed. |
|
223 |
$element['upload']['#theme_wrappers'][] = 'form_element__image_widget'; |
|
224 |
$element['upload']['#form_element_wrapper'] = FALSE; |
|
225 |
|
|
226 |
// Unfortunately, core also doesn't set #access on the appropriate elements |
|
227 |
// until way too late (ironically, because of #ajax). Instead of calling |
|
228 |
// file_managed_file_pre_render(), just mimic the same #access logic, but |
|
229 |
// using #default_value instead of #value since the ajax request populates |
|
230 |
// #value. |
|
231 |
$value = empty($element['#default_value']['fid']); |
|
232 |
if (!$value) { |
|
233 |
$element['upload']['#access'] = FALSE; |
|
234 |
$element['upload_button']['#access'] = FALSE; |
|
235 |
} |
|
236 |
// If we don't already have a file, there is nothing to remove. |
|
237 |
else { |
|
238 |
$element['remove_button']['#access'] = FALSE; |
|
239 |
} |
|
240 |
|
|
241 |
// Make the upload file element an input group with a button. |
|
242 |
$element['upload']['#input_group_button'] = $value; |
|
243 |
|
|
244 |
return $element; |
|
245 |
} |
|
246 |
|
|
202 | 247 |
/** |
203 | 248 |
* Implements hook_form_alter(). |
204 | 249 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules