protected function FileUpload::getUploadLocation in GraphQL 8.4
Determines the URI for a file field.
Parameters
array $settings: The array of field settings.
Return value
string An un-sanitized file directory URI with tokens replaced. The result of the token replacement is then converted to plain text and returned.
1 call to FileUpload::getUploadLocation()
- FileUpload::saveFileUpload in src/
GraphQL/ Utility/ FileUpload.php - Validates an uploaded file, saves it and returns a file upload response.
File
- src/
GraphQL/ Utility/ FileUpload.php, line 427
Class
- FileUpload
- Service to manage file uploads within GraphQL mutations.
Namespace
Drupal\graphql\GraphQL\UtilityCode
protected function getUploadLocation(array $settings) : string {
$destination = trim($settings['file_directory'], '/');
// Replace tokens first. This might produce cacheable metadata if tokens
// are used in the path. As this service is intended to be used in mutations
// which are not cached at all, it's enough to just catch leaked metadata
// and skip including them in current GraphQL field's context.
$context = new RenderContext();
$destination = $this->renderer
->executeInRenderContext($context, function () use ($destination) : string {
return $this->token
->replace($destination, []);
});
// As the tokens might contain HTML we convert it to plain text.
$destination = PlainTextOutput::renderFromHtml($destination);
return $settings['uri_scheme'] . '://' . $destination;
}