function imagefield_widget_process in ImageField 6.3
Element #process callback function.
1 string reference to 'imagefield_widget_process'
- imagefield_elements in ./
imagefield.module - Implementation of hook_elements().
File
- ./
imagefield_widget.inc, line 222 - ImageField widget hooks and callbacks.
Code
function imagefield_widget_process($element, $edit, &$form_state, $form) {
$file = $element['#value'];
$field = content_fields($element['#field_name'], $element['#type_name']);
$element['#theme'] = 'imagefield_widget_item';
if (isset($element['preview']) && $element['#value']['fid'] != 0) {
$element['preview']['#value'] = theme('imagefield_widget_preview', $element['#value']);
}
// Check if using the default alt text and replace tokens.
$default_alt = !$field['widget']['custom_alt'] || empty($file['status']) && empty($file['data']['alt']);
if ($default_alt && function_exists('token_replace')) {
$field['widget']['alt'] = empty($field['widget']['alt']) ? '' : token_replace($field['widget']['alt'], 'user', $GLOBALS['user']);
}
$element['data']['alt'] = array(
'#title' => t('Alternate Text'),
'#type' => $field['widget']['custom_alt'] ? 'textfield' : 'value',
'#default_value' => $default_alt ? $field['widget']['alt'] : $file['data']['alt'],
'#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
'#maxlength' => variable_get('imagefield_alt_length', 80),
// See http://www.gawds.org/show.php?contentid=28.
'#attributes' => array(
'class' => 'imagefield-text',
),
);
// #value must be hard-coded if #type = 'value'.
if ($default_alt) {
$element['data']['alt']['#value'] = $field['widget']['alt'];
}
// Check if using the default title and replace tokens.
$default_title = !$field['widget']['custom_title'] || empty($file['status']) && empty($file['data']['title']);
if ($default_title && function_exists('token_replace')) {
$field['widget']['title'] = empty($field['widget']['title']) ? '' : token_replace($field['widget']['title'], 'user', $GLOBALS['user']);
}
// If the custom title is enabled, input type defaults to textfield.
if (!empty($field['widget']['custom_title'])) {
$title_type = !empty($field['widget']['title_type']) ? $field['widget']['title_type'] : 'textfield';
}
else {
$title_type = 'value';
}
$element['data']['title'] = array(
'#type' => $title_type,
'#title' => t('Title'),
'#default_value' => $default_title ? $field['widget']['title'] : $file['data']['title'],
'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
'#maxlength' => variable_get('imagefield_title_length', 500),
'#attributes' => array(
'class' => 'imagefield-text',
),
);
// #value must be hard-coded if #type = 'value'.
if ($default_title) {
$element['data']['title']['#value'] = $field['widget']['title'];
}
return $element;
}