Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / file / src / Plugin / Field / FieldType / FileUriItem.php
1 <?php
2
3 namespace Drupal\file\Plugin\Field\FieldType;
4
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\Field\Plugin\Field\FieldType\UriItem;
7 use Drupal\Core\TypedData\DataDefinition;
8 use Drupal\file\ComputedFileUrl;
9
10 /**
11  * File-specific plugin implementation of a URI item to provide a full URL.
12  *
13  * @FieldType(
14  *   id = "file_uri",
15  *   label = @Translation("File URI"),
16  *   description = @Translation("An entity field containing a file URI, and a computed root-relative file URL."),
17  *   no_ui = TRUE,
18  *   default_formatter = "file_uri",
19  *   default_widget = "uri",
20  * )
21  */
22 class FileUriItem extends UriItem {
23
24   /**
25    * {@inheritdoc}
26    */
27   public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
28     $properties = parent::propertyDefinitions($field_definition);
29
30     $properties['url'] = DataDefinition::create('string')
31       ->setLabel(t('Root-relative file URL'))
32       ->setComputed(TRUE)
33       ->setInternal(FALSE)
34       ->setClass(ComputedFileUrl::class);
35
36     return $properties;
37   }
38
39 }