function FileItem::doGetUploadLocation

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::doGetUploadLocation()
  2. 8.9.x core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::doGetUploadLocation()
  3. 10 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::doGetUploadLocation()

Determines the URI for a file field.

Parameters

array $settings: The array of field settings.

array $data: An array of token objects to pass to Token::replace().

Return value

string An unsanitized file directory URI with tokens replaced. The result of the token replacement is then converted to plain text and returned.

See also

\Drupal\Core\Utility\Token::replace()

3 calls to FileItem::doGetUploadLocation()
FileItem::generateSampleValue in core/modules/file/src/Plugin/Field/FieldType/FileItem.php
FileItem::getUploadLocation in core/modules/file/src/Plugin/Field/FieldType/FileItem.php
Determines the URI for a file field.
ImageItem::generateSampleValue in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php

File

core/modules/file/src/Plugin/Field/FieldType/FileItem.php, line 332

Class

FileItem
Plugin implementation of the 'file' field type.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

protected static function doGetUploadLocation(array $settings, $data = []) {
    $destination = trim($settings['file_directory'], '/');
    // Replace tokens. As the tokens might contain HTML we convert it to plain
    // text.
    $destination = PlainTextOutput::renderFromHtml(\Drupal::token()->replace($destination, $data));
    return $settings['uri_scheme'] . '://' . $destination;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.