You are here

protected function DropzoneJsUploadSave::prepareDestination in DropzoneJS 8

Same name and namespace in other branches
  1. 8.2 src/DropzoneJsUploadSave.php \Drupal\dropzonejs\DropzoneJsUploadSave::prepareDestination()

Validate and set destination the destination URI.

Parameters

\Drupal\file\FileInterface $file: The file entity object.

string $destination: A string containing the URI that the file should be copied to. This must be a stream wrapper URI.

Return value

bool True if the destination was sucesfully validated and set, otherwise false.

1 call to DropzoneJsUploadSave::prepareDestination()
DropzoneJsUploadSave::createFile in src/DropzoneJsUploadSave.php
Creates a file entity form an uploaded file.

File

src/DropzoneJsUploadSave.php, line 218

Class

DropzoneJsUploadSave
A service that saves files uploaded by the dropzonejs element as files.

Namespace

Drupal\dropzonejs

Code

protected function prepareDestination(FileInterface $file, $destination) {

  // Assert that the destination contains a valid stream.
  $destination_scheme = $this->fileSystem
    ->uriScheme($destination);
  if (!$this->fileSystem
    ->validScheme($destination_scheme)) {
    return FALSE;
  }

  // Prepare the destination dir.
  if (!file_exists($destination)) {
    $this->fileSystem
      ->mkdir($destination, NULL, TRUE);
  }

  // A file URI may already have a trailing slash or look like "public://".
  if (substr($destination, -1) != '/') {
    $destination .= '/';
  }
  $destination = file_destination($destination . $file
    ->getFilename(), FILE_EXISTS_RENAME);
  $file
    ->setFileUri($destination);
  return TRUE;
}