You are here

public function File::createFileUrl in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::createFileUrl()
  2. 9 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::createFileUrl()

Creates a file URL for the URI of this file.

Parameters

bool $relative: (optional) Whether the URL should be root-relative, defaults to TRUE.

Return value

string A string containing a URL that may be used to access the file.

Overrides FileInterface::createFileUrl

See also

\Drupal\Core\File\FileUrlGeneratorInterface

File

core/modules/file/src/Entity/File.php, line 81

Class

File
Defines the file entity class.

Namespace

Drupal\file\Entity

Code

public function createFileUrl($relative = TRUE) {

  /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
  $file_url_generator = \Drupal::service('file_url_generator');
  return $relative ? $file_url_generator
    ->generateString($this
    ->getFileUri()) : $file_url_generator
    ->generateAbsoluteString($this
    ->getFileUri());
}