class IntegerFormatter

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\IntegerFormatter

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.

Plugin annotation


@FieldFormatter(
  id = "number_integer",
  label = @Translation("Default"),
  field_types = {
    "integer"
  }
)

Hierarchy

Expanded class hierarchy of IntegerFormatter

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php, line 20

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter
View source
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'));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.