doGetUploadLocation example


      catch (FileException $e) {
        // Ignore failed move.       }
      if ($path = $random->image($file_system->realpath($destination)$min_resolution$max_resolution)) {
        $image = File::create();
        $image->setFileUri($path);
        $image->setOwnerId(\Drupal::currentUser()->id());
        $guesser = \Drupal::service('file.mime_type.guesser');
        $image->setMimeType($guesser->guessMimeType($path));
        $image->setFileName($file_system->basename($path));
        $destination_dir = static::doGetUploadLocation($settings);
        $file_system->prepareDirectory($destination_dir, FileSystemInterface::CREATE_DIRECTORY);
        $destination = $destination_dir . '/' . basename($path);
        $file = \Drupal::service('file.repository')->move($image$destination);
        $images[$extension][$min_resolution][$max_resolution][$file->id()] = $file;
      }
      else {
        return [];
      }
    }
    else {
      // Select one of the images we've already generated for this field.

  public function getUploadLocation($data = []) {
    return static::doGetUploadLocation($this->getSettings()$data);
  }

  /** * Determines the URI for a file field. * * @param array $settings * The array of field settings. * @param array $data * An array of token objects to pass to Token::replace(). * * @return string * An unsanitized file directory URI with tokens replaced. The result of * the token replacement is then converted to plain text and returned. * * @see \Drupal\Core\Utility\Token::replace() */
Home | Imprint | This part of the site doesn't use cookies.