You are here

public function File::getUrl in Linkit 8.5

Get the URL associated with a given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to get a URL for.

Return value

\Drupal\Core\GeneratedUrl A url to replace.

Overrides SubstitutionInterface::getUrl

File

src/Plugin/Linkit/Substitution/File.php, line 24

Class

File
A substitution plugin for the URL to a file.

Namespace

Drupal\linkit\Plugin\Linkit\Substitution

Code

public function getUrl(EntityInterface $entity) {
  $url = new GeneratedUrl();

  /** @var \Drupal\file\FileInterface $entity */
  $url
    ->setGeneratedUrl(file_create_url($entity
    ->getFileUri()));
  $url
    ->addCacheableDependency($entity);
  return $url;
}