I have Drupal custom module with a form and a number of fields in it. File upload is one of them, it's working fine. But I need to preprocess image before uploading, preferably with Image module. Here's what I have in submitForm:

  if ($form_state->getValue('image') != NULL) {
  $form_file = $form_state->getValue('image', 0);
  if (isset($form_file[0]) && !empty($form_file[0])) {
    $file = File::load($form_file[0]);
    $image = $file->getFilename();
    $fields['image'] = $image;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.