You are here

function imagefield_widget_upload_validators in ImageField 6.3

Get the additional upload validators for an image field.

Parameters

$field: The CCK field array.

Return value

An array suitable for passing to file_save_upload() or the file field element's '#upload_validators' property.

1 call to imagefield_widget_upload_validators()
imagefield_widget in ./imagefield.module
Implementation of CCK's hook_widget().

File

./imagefield.module, line 205

Code

function imagefield_widget_upload_validators($field) {
  $validators = array();

  // Match the default value if no file extensions have been saved at all.
  if (!isset($field['widget']['file_extensions'])) {
    $field['widget']['file_extensions'] = 'png gif jpg jpeg';
  }

  // Ensure that only web images are supported.
  $web_extensions = array(
    'png',
    'gif',
    'jpg',
    'jpeg',
  );
  $extensions = array_filter(explode(' ', $field['widget']['file_extensions']));
  if (empty($extensions)) {
    $extensions = $web_extensions;
  }
  $validators['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions));

  // Add the image validator as a basic safety check.
  $validators['filefield_validate_is_image'] = array();

  // Add validators for resolutions.
  if (!empty($field['widget']['max_resolution']) || !empty($field['widget']['min_resolution'])) {
    $validators['filefield_validate_image_resolution'] = array(
      $field['widget']['max_resolution'],
      $field['widget']['min_resolution'],
    );
  }
  return $validators;
}