You are here

function dynamic_background_upload_form_process in Dynamic Background 6

Same name and namespace in other branches
  1. 7.2 includes/upload.form.inc \dynamic_background_upload_form_process()
  2. 7 includes/upload.form.inc \dynamic_background_upload_form_process()

Implementation of hook_form_process(). Handles the background_upload_form element processing and building.

1 string reference to 'dynamic_background_upload_form_process'
dynamic_background_elements in includes/upload.form.inc
Implementation of hook_elements().

File

includes/upload.form.inc, line 54
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) {
  $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 (isset($element['#value']['default'])) {

    // Create image preview thumbnail, using imagecache.
    $picture = theme('imagecache', 'dynamic_background_thumb', $element['#value']['default'], basename($element['#value']['default']), basename($element['#value']['default']), NULL);
    $element['current_picture'] = array(
      '#value' => $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' => $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' => $element['#value']['picture_delete'],
    );
  }
  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/admin_form.css', 'module');
  drupal_add_js(drupal_get_path('module', 'dynamic_background') . '/js/dynamic_background.js', 'module');
  return $element;
}