trait FileUploadLocationTrait
Resolves the file upload location from a file field definition.
Hierarchy
- trait \Drupal\file\Upload\FileUploadLocationTrait
 
3 files declare their use of FileUploadLocationTrait
- FileUpload.php in core/
modules/ jsonapi/ src/ Controller/ FileUpload.php  - FileUploadResource.php in core/
modules/ file/ src/ Plugin/ rest/ resource/ FileUploadResource.php  - TemporaryJsonapiFileFieldUploader.php in core/
modules/ jsonapi/ src/ Controller/ TemporaryJsonapiFileFieldUploader.php  
File
- 
              core/
modules/ file/ src/ Upload/ FileUploadLocationTrait.php, line 13  
Namespace
Drupal\file\UploadView source
trait FileUploadLocationTrait {
  
  /**
   * Resolves the file upload location from a file field definition.
   *
   * @param \Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition
   *   The file field definition.
   *
   * @return string
   *   An un-sanitized file directory URI with tokens replaced. The result of
   *   the token replacement is then converted to plain text and returned.
   */
  public function getUploadLocation(FieldDefinitionInterface $fieldDefinition) : string {
    assert(is_a($fieldDefinition->getClass(), FileFieldItemList::class, TRUE));
    $fieldItemDataDefinition = FieldItemDataDefinition::create($fieldDefinition);
    $fileItem = new FileItem($fieldItemDataDefinition);
    return $fileItem->getUploadLocation();
  }
}
Members
| Title Sort descending | Modifiers | Object type | Summary | 
|---|---|---|---|
| FileUploadLocationTrait::getUploadLocation | public | function | Resolves the file upload location from a file field definition. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.