Version 1
[yaffs-website] / web / core / modules / file / src / Plugin / Field / FieldFormatter / UrlPlainFormatter.php
1 <?php
2
3 namespace Drupal\file\Plugin\Field\FieldFormatter;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6
7 /**
8  * Plugin implementation of the 'file_url_plain' formatter.
9  *
10  * @FieldFormatter(
11  *   id = "file_url_plain",
12  *   label = @Translation("URL to file"),
13  *   field_types = {
14  *     "file"
15  *   }
16  * )
17  */
18 class UrlPlainFormatter extends FileFormatterBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function viewElements(FieldItemListInterface $items, $langcode) {
24     $elements = [];
25
26     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
27       $elements[$delta] = [
28         '#markup' => file_url_transform_relative(file_create_url($file->getFileUri())),
29         '#cache' => [
30           'tags' => $file->getCacheTags(),
31         ],
32       ];
33     }
34
35     return $elements;
36   }
37
38 }