Determines the URI for a file field instance.
$field: A field array.
$instance: A field instance array.
$data: An array of token objects to pass to \Drupal\Core\Utility\Token::replace().
A file directory URI with tokens replaced.
\Drupal\Core\Utility\Token::replace()
function file_field_widget_uri($field, $instance, $data = array()) {
$destination = trim($instance['settings']['file_directory'], '/');
// Replace tokens.
$destination = Drupal::token()
->replace($destination, $data);
return $field['settings']['uri_scheme'] . '://' . $destination;
}