Version 1
[yaffs-website] / web / core / modules / views / tests / modules / views_test_formatter / src / Plugin / Field / FieldFormatter / AttachmentTestFormatter.php
diff --git a/web/core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php b/web/core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
new file mode 100644 (file)
index 0000000..bfee627
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\views_test_formatter\Plugin\Field\FieldFormatter;
+
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericUnformattedFormatter;
+
+/**
+ * Plugin implementation of the 'number_unformatted_with_attachment' formatter.
+ *
+ * @FieldFormatter(
+ *   id = "number_unformatted_with_attachment",
+ *   label = @Translation("Unformatted, with attachments"),
+ *   field_types = {
+ *     "integer",
+ *     "decimal",
+ *     "float"
+ *   }
+ * )
+ */
+class AttachmentTestFormatter extends NumericUnformattedFormatter {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function viewElements(FieldItemListInterface $items, $langcode) {
+    $elements = parent::viewElements($items, $langcode);
+
+    // Add dummy attachments.
+    $entity_id = $items->getEntity()->id();
+    $elements['#attached']['library'][] = 'foo/fake_library';
+    $elements['#attached']['drupalSettings']['AttachmentIntegerFormatter'][$entity_id] = $entity_id;
+
+    return $elements;
+  }
+
+}