function dynamic_background_upload_form_process in Dynamic Background 7
Same name and namespace in other branches
- 6 includes/upload.form.inc \dynamic_background_upload_form_process()
- 7.2 includes/upload.form.inc \dynamic_background_upload_form_process()
Implements hook_form_process(). Handles the background_upload_form element processing and building.
1 string reference to 'dynamic_background_upload_form_process'
- dynamic_background_element_info in includes/
upload.form.inc - Implements hook_elements().
File
- includes/
upload.form.inc, line 44 - The functions here is used to create an new form element (background_upload_form), which can be used to upload images. It also gives the possibility to flag a image for deletion or active background image.
Code
function dynamic_background_upload_form_process($element, &$form_state, $form) {
$element['#tree'] = TRUE;
// Merge the default values.
if (!isset($element['#value'])) {
$element['#value'] = $element['#default_value'];
}
else {
if (is_array($element['#default_value'])) {
$element['#value'] = array_merge($element['#value'], $element['#default_value']);
}
}
// If image is already uploaded
if (!empty($element['#value']['picture'])) {
// Create image preview thumbnail.
$image = array(
'style_name' => 'thumbnail',
'path' => $element['#value']['picture'],
'alt' => basename($element['#value']['picture']),
'title' => basename($element['#value']['picture']),
);
$picture = theme('image_style', $image);
$element['current_picture'] = array(
'#markup' => $picture,
);
// Checkbox to indicate if this image should be used as background image.
$element['picture_use'] = array(
'#type' => 'checkbox',
'#title' => t('Use picture as background'),
'#default_value' => isset($element['#value']['picture_use']) ? $element['#value']['picture_use'] : '',
'#prefix' => '<div class="picture-use">',
'#suffix' => '</div>',
);
// Checkbox to control deletion of the image.
$element['picture_delete'] = array(
'#type' => 'checkbox',
'#title' => t('Delete picture'),
'#default_value' => isset($element['#value']['picture_delete']) ? $element['#value']['picture_delete'] : '',
);
// Image path used by the administraion UI.
$element['picture'] = array(
'#type' => 'hidden',
'#default_value' => isset($element['#value']['picture']) ? $element['#value']['picture'] : '',
);
// Image file id, used when the file is deleted.
$element['fid'] = array(
'#type' => 'hidden',
'#default_value' => isset($element['#value']['fid']) ? $element['#value']['fid'] : '',
);
}
else {
// No image uploaded, so display image upload field.
$element['picture'] = array(
'#type' => 'file',
'#description' => t('Select image file to upload'),
);
}
// Load styling and js.
drupal_add_css(drupal_get_path('module', 'dynamic_background') . '/css/dynamic_background.admin.css', 'module');
drupal_add_js(drupal_get_path('module', 'dynamic_background') . '/js/dynamic_background.js', 'file');
return $element;
}