Exploiting the file_save_upload functions options, i would like to give a different treatment to the file on media replace.
- if the new file to upload has the same uri than the existing, i would like to use FILE_EXISTS_REPLACE
- if the new file to upload has a different URI, i would like to use FILE_EXISTS_RENAME
something like:
/** * Custom validate handler for media entity edit form submissions. */ function hook_validate($form, FormStateInterface $formState) { //if replacement file has same uri as original $replacementFile = file_save_upload('replacement_file', $uploadValidators, $uploadDestination, 0, FileSystemInterface::EXISTS_RENAME); //else $replacementFile = file_save_upload('replacement_file', $uploadValidators, $uploadDestination, 0, FileSystemInterface::EXISTS_REPLACE); }