Version 1
[yaffs-website] / web / core / modules / file / src / Plugin / Field / FieldFormatter / UrlPlainFormatter.php
diff --git a/web/core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php b/web/core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php
new file mode 100644 (file)
index 0000000..d5e2a7c
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace Drupal\file\Plugin\Field\FieldFormatter;
+
+use Drupal\Core\Field\FieldItemListInterface;
+
+/**
+ * Plugin implementation of the 'file_url_plain' formatter.
+ *
+ * @FieldFormatter(
+ *   id = "file_url_plain",
+ *   label = @Translation("URL to file"),
+ *   field_types = {
+ *     "file"
+ *   }
+ * )
+ */
+class UrlPlainFormatter extends FileFormatterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function viewElements(FieldItemListInterface $items, $langcode) {
+    $elements = [];
+
+    foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
+      $elements[$delta] = [
+        '#markup' => file_url_transform_relative(file_create_url($file->getFileUri())),
+        '#cache' => [
+          'tags' => $file->getCacheTags(),
+        ],
+      ];
+    }
+
+    return $elements;
+  }
+
+}