You are here

function imagefield_crop_value_callback in Imagefield Crop 7.3

Same name and namespace in other branches
  1. 7.2 imagefield_crop.module \imagefield_crop_value_callback()

Element value callback. Used to set crop area to image size, if image is smaller then output resolution, but validation isn't enabled.

Parameters

$element:

bool $input:

$form_state:

Return value

array|bool

1 string reference to 'imagefield_crop_value_callback'
imagefield_crop_field_widget_form in ./imagefield_crop.module
Implements hook_field_widget_form().

File

./imagefield_crop.module, line 834

Code

function imagefield_crop_value_callback($element, $input = FALSE, $form_state) {
  $crop_config = array();

  // We depend on the managed file element to handle uploads.
  $return = file_managed_file_value($element, $input, $form_state);
  $form_state_crop_config = $form_state['values'];
  foreach ($element['#parents'] as $parent) {
    $form_state_crop_config = isset($form_state_crop_config[$parent]) ? $form_state_crop_config[$parent] : array();
  }
  if (isset($form_state_crop_config['crop_config'])) {
    foreach ($form_state_crop_config['crop_config'] as $pid => $preset) {
      if (!is_object($preset)) {
        $crop_config[$pid] = json_decode($preset);
      }
      else {
        $crop_config[$pid] = $preset;
      }
    }
  }
  if (!empty($return['crop_config']) && $input) {
    $crop_config = $return['crop_config'];
    foreach ($crop_config as $pid => &$config) {
      $config = json_decode($config);
    }
  }

  //  hook_value_vallback should return values only from form.
  if (!empty($crop_config)) {
    $return['crop_config'] = $crop_config;
  }
  return $return;
}