1 image.field.inc _image_field_default_image_validate($element, &$form_state)

Element validation function for setting a default image.

File

core/modules/image/image.field.inc, line 267
Implement an image field, based on the file module's file field.

Code

function _image_field_default_image_validate($element, &$form_state) {
  // Save the file into the temporary directory.
  $file = file_save_upload(implode('_', $element['file']['#parents']), array('file_validate_is_image' => array()));

  if ($file) {
    // Move the file to the final location, and don't manage it in the database.
    // Because field configurations should not be tied to database auto-increment
    // IDs, we only track the URI.
    $directory = $element['#default_scheme'] . '://default_images/';
    file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
    $uri = file_unmanaged_move($file->uri, $directory);

    // Delete the file entity record.
    file_delete($file->fid);
  }
  if (isset($element['remove']) && $element['remove']['#value']) {
    $uri = '';
  }

  if (isset($uri)) {
    backdrop_array_set_nested_value($form_state['values'], $element['#target'], $uri, TRUE);
  }
  else {
    backdrop_array_unset_nested_value($form_state['values'], $element['#target']);
  }
}