function imagefield_extended_widget_process in ImageField Extended 6.3
Same name and namespace in other branches
- 6.4 imagefield_extended.module \imagefield_extended_widget_process()
Element #process callback function.
1 string reference to 'imagefield_extended_widget_process'
- imagefield_extended_elements in ./
imagefield_extended.module - Implementation of hook_elements().
File
- ./
imagefield_extended.module, line 236 - Insert additional fields into an ImageField data array.
Code
function imagefield_extended_widget_process($element, $edit, &$form_state, $form) {
$file = $element['#value'];
$field = content_fields($element['#field_name'], $element['#type_name']);
$widget = $field['widget'];
$extra_values = isset($element['#value']['data']) ? $element['#value']['data'] : array();
// Load the internal fields we present
$extended_fields = _imagefield_extended_fields();
foreach ($extended_fields['textfields'] as $key => $title) {
if (!empty($widget['custom_' . $key])) {
$element['data'][$key]['body'] = array(
'#type' => $widget['custom_' . $key . '_style'] != 'textfield' ? 'textarea' : 'textfield',
'#required' => $widget['custom_' . $key . '_required'] ? TRUE : FALSE,
'#title' => drupal_ucfirst($title),
'#default_value' => isset($extra_values[$key]['body']) ? $extra_values[$key]['body'] : $widget[$key],
'#attributes' => array(
'class' => 'imagefield-text',
),
);
if (!empty($widget[$key . '_help'])) {
$element['data'][$key]['body']['#description'] = $widget[$key . '_help'];
}
if ($widget['custom_' . $key . '_style'] == 'formatted') {
$element['data'][$key]['format'] = filter_form($extra_values[$key]['format'], NULL, array_merge($element['#array_parents'], array(
'data',
$key,
'format',
)));
}
else {
$element['data'][$key]['format'] = array(
'#type' => 'hidden',
'#value' => isset($extra_values[$key]['format']) ? $extra_values[$key]['format'] : '',
);
}
$element['data'][$key]['style'] = array(
'#type' => 'hidden',
'#value' => $widget['custom_' . $key . '_style'],
);
}
}
foreach ($extended_fields['checkboxes'] as $key => $title) {
if (!empty($widget['workflow_' . $key])) {
$element['data']['workflow_' . $key] = array(
'#type' => 'checkbox',
'#title' => drupal_ucfirst($title),
'#default_value' => isset($extra_values['workflow_' . $key]) ? $extra_values['workflow_' . $key] : 0,
'#attributes' => array(
'class' => 'imagefield-checkbox',
),
'#suffix' => '<div class="clear"></div>',
);
}
}
$extra_fields = module_invoke_all('imagefield_extended_widget', $element, $extra_values);
foreach ($extra_fields as $key => $field) {
$element['data'][$key] = $field;
}
return $element;
}