Pull merge.
[yaffs-website] / web / core / modules / file / src / ComputedFileUrl.php
1 <?php
2
3 namespace Drupal\file;
4
5 use Drupal\Core\TypedData\TypedData;
6
7 /**
8  * Computed file URL property class.
9  */
10 class ComputedFileUrl extends TypedData {
11
12   /**
13    * Computed root-relative file URL.
14    *
15    * @var string
16    */
17   protected $url = NULL;
18
19   /**
20    * {@inheritdoc}
21    */
22   public function getValue() {
23     if ($this->url !== NULL) {
24       return $this->url;
25     }
26
27     assert($this->getParent()->getEntity() instanceof FileInterface);
28
29     $uri = $this->getParent()->getEntity()->getFileUri();
30     $this->url = file_url_transform_relative(file_create_url($uri));
31
32     return $this->url;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function setValue($value, $notify = TRUE) {
39     $this->url = $value;
40
41     // Notify the parent of any changes.
42     if ($notify && isset($this->parent)) {
43       $this->parent->onChange($this->name);
44     }
45   }
46
47 }