You are here

public static function BlockUploadBuild::blockUploadGetUploadDestination in Block Upload 8

Returns destinaton for file upload.

Return value

string Destination path.

1 call to BlockUploadBuild::blockUploadGetUploadDestination()
BlockUploadForm::buildForm in src/Form/BlockUploadForm.php
Form constructor.

File

src/BlockUploadBuild.php, line 70

Class

BlockUploadBuild
BlockUploadBuild class.

Namespace

Drupal\block_upload

Code

public static function blockUploadGetUploadDestination($field) {
  if ($destination = $field
    ->getSetting('file_directory')) {
    if (\Drupal::request()->attributes
      ->has('node')) {
      $node = \Drupal::request()->attributes
        ->get('node');
    }
    $token = \Drupal::token();
    $destination = $token
      ->replace($destination, [
      'node' => $node,
    ]);
  }
  $field_info = FieldStorageConfig::loadByName($field
    ->get('entity_type'), $field
    ->getName());
  $uri_scheme = $field_info
    ->getSetting('uri_scheme');
  if (!$uri_scheme) {
    $uri_scheme = 'public';
  }
  $destination = $uri_scheme . '://' . $destination;
  \Drupal::service('file_system')
    ->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY);
  return $destination;
}