ComputedFileUrl.php in Drupal 9
File
core/modules/file/src/ComputedFileUrl.php
View source
<?php
namespace Drupal\file;
use Drupal\Core\TypedData\TypedData;
class ComputedFileUrl extends TypedData {
protected $url = NULL;
public function getValue() {
if ($this->url !== NULL) {
return $this->url;
}
assert($this
->getParent()
->getEntity() instanceof FileInterface);
$uri = $this
->getParent()
->getEntity()
->getFileUri();
$file_url_generator = \Drupal::service('file_url_generator');
$this->url = $file_url_generator
->generateString($uri);
return $this->url;
}
public function setValue($value, $notify = TRUE) {
$this->url = $value;
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
}