You are here

function variable_file_form_image_process in Variable Extra 7

An element #process callback for the image_image field type.

Expands the image_image type to include the alt and title fields.

2 string references to 'variable_file_form_image_process'
variable_file_form_element_file_display in variable_file/variable_file.variable.inc
Display file information element.
variable_file_form_element_file_managed in variable_file/variable_file.variable.inc
Build upload file variable.

File

variable_file/variable_file.module, line 13

Code

function variable_file_form_image_process($element, &$form_state, $form) {
  $variable = $element['#variable'];
  $element['#theme'] = 'image_widget';
  $element['#attached']['css'][] = drupal_get_path('module', 'image') . '/image.css';

  // Add the image preview.
  if ($element['#file']) {
    $variables = array(
      'style_name' => $variable['image style'],
      'path' => $element['#file']->uri,
    );

    // Determine image dimensions.
    if (isset($element['#value']['width']) && isset($element['#value']['height'])) {
      $variables['width'] = $element['#value']['width'];
      $variables['height'] = $element['#value']['height'];
    }
    else {
      $info = image_get_info($element['#file']->uri);
      if (is_array($info)) {
        $variables['width'] = $info['width'];
        $variables['height'] = $info['height'];
      }
      else {
        $variables['width'] = $variables['height'] = NULL;
      }
    }
    $element['preview'] = array(
      '#type' => 'markup',
      '#markup' => theme('image_style', $variables),
    );

    // Store the dimensions in the form so the file doesn't have to be accessed
    // again. This is important for remote files.
    $element['width'] = array(
      '#type' => 'hidden',
      '#value' => $variables['width'],
    );
    $element['height'] = array(
      '#type' => 'hidden',
      '#value' => $variables['height'],
    );
  }
  return $element;
}