Drupal 8: Upload Validation form alterations ignored I'm trying to ignore the auto down scaling of large images and replace the validation step with a hard check that the size matches the maximum size provided. I'm trying to do this through the HOOK_form_alter hook and while it appears to be affecting the form render array, the AJAX request seems to ignore my changes and run the default upload validation steps.

Here's what i'm doing:
In the seven.theme file:

function seven_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $imageForValidation = NULL;

  if (isset($form['field_name_here'])) {
    $imageForValidation = $form['field_name_here'];
  }

  if ($imageForValidation != NULL) {
    // Validate
    $imageForValidation['widget'][0]['#upload_validators']['myTheme_image_validator'] = array();
    unset($imageForValidation['widget'][0]['#upload_validators']['file_validate_image_resolution']);
  }

  return $form;
}

function myTheme_image_validator($file) {
  $errors = array();

  // This doesn't even get called.

  return $errors;
}


I've debugged with xdebug and the render array is indeed getting affected, but the result of uploading an image is always the same as the default setup. At the very least I expect the unset validator to not get run, but it still downscales.

Has anyone got round this issue before?
Clive was spot on. Turns out I wasn't passing my variable by reference. I was thrown off by (what is now old hat in Drupal 8) returning the form variable at the end of the form_alter hook.