class FileLinkTarget
Provides a File link target handler.
File entities are atypical because they are not served by Drupal, but by the web server.
Hierarchy
- class \Drupal\file\Entity\FileLinkTarget implements \Drupal\Core\Entity\EntityLinkTargetInterface
Expanded class hierarchy of FileLinkTarget
See also
\Drupal\file\FileInterface::createFileUrl()
\Drupal\Core\File\FileUrlGeneratorInterface
File
-
core/
modules/ file/ src/ Entity/ FileLinkTarget.php, line 22
Namespace
Drupal\file\EntityView source
class FileLinkTarget implements EntityLinkTargetInterface {
/**
* {@inheritdoc}
*/
public function getLinkTarget(EntityInterface $entity) : GeneratedUrl {
assert($entity instanceof FileInterface);
$url = $entity->createFileUrl(TRUE);
// The $url is a string, which provides no cacheability metadata.
assert(is_string($url));
return (new GeneratedUrl())->setGeneratedUrl($url)
->setCacheMaxAge(Cache::PERMANENT);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.