function FileLinkTarget::getLinkTarget

Gets the generated URL object for a linked entity's link target.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A linked entity.

Return value

\Drupal\Core\GeneratedUrl The generated URL plus cacheability metadata.

Overrides EntityLinkTargetInterface::getLinkTarget

File

core/modules/file/src/Entity/FileLinkTarget.php, line 27

Class

FileLinkTarget
Provides a File link target handler.

Namespace

Drupal\file\Entity

Code

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.