D8 Pragmatically - pierregermain/MyDrupal GitHub Wiki
Get File Path
protected function getFilePath($fid) {
$file_storage = \Drupal::entityTypeManager()->getStorage('file');
$file = $file_storage->load($fid);
$fileUri = $file->getFileUri();
$filePath = $this->publicFilePath . file_url_transform_relative(file_create_url($fileUri));
return $filePath;
}
Redirect giving field_name
// Redirect to destination url.
$destination_uri = $entity->get('field_name')->getValue()['0']['uri'];
$url = Url::fromUri($destination_uri);
$destination = $url->toString();
$response = new RedirectResponse($destination, 301);
$response->send();