IntegerFormatter.php 871 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
  3. /**
  4. * Plugin implementation of the 'number_integer' formatter.
  5. *
  6. * The 'Default' formatter is different for integer fields on the one hand, and
  7. * for decimal and float fields on the other hand, in order to be able to use
  8. * different settings.
  9. *
  10. * @FieldFormatter(
  11. * id = "number_integer",
  12. * label = @Translation("Default"),
  13. * field_types = {
  14. * "integer"
  15. * }
  16. * )
  17. */
  18. class IntegerFormatter extends NumericFormatterBase {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function defaultSettings() {
  23. return [
  24. 'thousand_separator' => '',
  25. 'prefix_suffix' => TRUE,
  26. ] + parent::defaultSettings();
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. protected function numberFormat($number) {
  32. return number_format($number, 0, '', $this->getSetting('thousand_separator'));
  33. }
  34. }