UploadMediaForm::submitForm has hard coded the public file scheme as the destination:

if (file_exists('public://' . $file['filename'])) {
  $this->logger->notice($this->t('File @filename already exists - It has been replaced', ['@filename' => $file['filename']]));
  drupal_set_message($this->t('File @filename already exists - It has been replaced', ['@filename' => $file['filename']]));
}
$file_entity = file_save_data($data, 'public://' . $file['filename'], FILE_EXISTS_REPLACE);

Drupal comes with a second uri scheme,

private://

and allows additional schemes/stream wrappers to be defined. The file destination is configured in the destination field, so let's use that.

Patch follows.

Comments

FatherShawn created an issue. See original summary.

fathershawn’s picture

StatusFileSize
new3.18 KB
fathershawn’s picture

Status: Active » Needs review
fathershawn’s picture

StatusFileSize
new3.18 KB

Unintentional trailing comma removed.

fathershawn’s picture

Further testing shows we should also pull in the path configuration from the field settings.

treuliaux’s picture

I'm sorry to ask you this, but could you make a third version of your patch with the last version I pushed on dev please ?

fathershawn’s picture

StatusFileSize
new4.02 KB

Here is an updated patch that makes use of the scheme and the upload directory settings.

And a re-roll against HEAD is always a fair ask, even if I wasn't adding an improvement!

treuliaux’s picture

StatusFileSize
new4.16 KB

Thanks for the update !

I just had to make slight changes to keep phpcs from yelling at me.

I'll push this patch on dev tomorrow !

  • treuliaux committed 68cddb3 on 8.x-1.x authored by FatherShawn
    Issue #2901027 by FatherShawn, treuliaux: UploadMediaForm::submitForm...
treuliaux’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.