Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Field / Plugin / Field / FieldFormatter / IntegerFormatter.php
diff --git a/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php b/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php
new file mode 100644 (file)
index 0000000..058de4d
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
+
+/**
+ * Plugin implementation of the 'number_integer' formatter.
+ *
+ * The 'Default' formatter is different for integer fields on the one hand, and
+ * for decimal and float fields on the other hand, in order to be able to use
+ * different settings.
+ *
+ * @FieldFormatter(
+ *   id = "number_integer",
+ *   label = @Translation("Default"),
+ *   field_types = {
+ *     "integer"
+ *   }
+ * )
+ */
+class IntegerFormatter extends NumericFormatterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function defaultSettings() {
+    return [
+      'thousand_separator' => '',
+      'prefix_suffix' => TRUE,
+    ] + parent::defaultSettings();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function numberFormat($number) {
+    return number_format($number, 0, '', $this->getSetting('thousand_separator'));
+  }
+
+}