class ComputedFileUrl
Same name in other branches
- 8.9.x core/modules/file/src/ComputedFileUrl.php \Drupal\file\ComputedFileUrl
- 10 core/modules/file/src/ComputedFileUrl.php \Drupal\file\ComputedFileUrl
- 11.x core/modules/file/src/ComputedFileUrl.php \Drupal\file\ComputedFileUrl
Computed file URL property class.
Hierarchy
- class \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\TypedDataInterface, \Drupal\Component\Plugin\PluginInspectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\TypedData\TypedDataTrait
- class \Drupal\file\ComputedFileUrl extends \Drupal\Core\TypedData\TypedData
Expanded class hierarchy of ComputedFileUrl
2 files declare their use of ComputedFileUrl
- ComputedFileUrlTest.php in core/
modules/ file/ tests/ src/ Kernel/ ComputedFileUrlTest.php - FileUriItem.php in core/
modules/ file/ src/ Plugin/ Field/ FieldType/ FileUriItem.php
File
-
core/
modules/ file/ src/ ComputedFileUrl.php, line 10
Namespace
Drupal\fileView source
class ComputedFileUrl extends TypedData {
/**
* Computed root-relative file URL.
*
* @var string
*/
protected $url = NULL;
/**
* {@inheritdoc}
*/
public function getValue() {
if ($this->url !== NULL) {
return $this->url;
}
assert($this->getParent()
->getEntity() instanceof FileInterface);
$uri = $this->getParent()
->getEntity()
->getFileUri();
/** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
$file_url_generator = \Drupal::service('file_url_generator');
$this->url = $file_url_generator->generateString($uri);
return $this->url;
}
/**
* {@inheritdoc}
*/
public function setValue($value, $notify = TRUE) {
$this->url = $value;
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.