function file_entity_edit_validate in File Entity (fieldable files) 7.2
Same name and namespace in other branches
- 7.3 file_entity.pages.inc \file_entity_edit_validate()
- 7 file_entity.pages.inc \file_entity_edit_validate()
Form validation handler for file_entity_edit().
1 string reference to 'file_entity_edit_validate'
- file_entity_edit in ./file_entity.pages.inc 
- Page callback: Form constructor for the file edit form.
File
- ./file_entity.pages.inc, line 950 
- Supports file operations including View, Edit, and Delete.
Code
function file_entity_edit_validate($form, &$form_state) {
  $file = (object) $form_state['values'];
  // Validate the "associated user" field.
  if (!empty($file->name) && !($account = user_load_by_name($file->name))) {
    // The use of empty() is mandatory in the context of usernames
    // as the empty string denotes the anonymous user. In case we
    // are dealing with an anonymous user we set the user ID to 0.
    form_set_error('name', t('The username %name does not exist.', array(
      '%name' => $file->name,
    )));
  }
  // Handle the replacement file if uploaded.
  if (isset($form_state['values']['replace_upload'])) {
    // Save the file as a temporary file.
    $file = file_save_upload('replace_upload', $form['replace_upload']['#upload_validators']);
    if (!empty($file)) {
      // Put the temporary file in form_values so we can save it on submit.
      $form_state['values']['replace_upload'] = $file;
    }
    elseif ($file === FALSE) {
      // File uploaded failed.
      form_set_error('replace_upload', t('The replacement file could not be uploaded.'));
    }
  }
  // Run entity form validation.
  entity_form_field_validate('file', $form, $form_state);
}