IntegerFormatter.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php
  3. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/IntegerFormatter.php

View source
<?php

namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * 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.
 */
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'));
    }

}

Classes

Title Deprecated Summary
IntegerFormatter Plugin implementation of the 'number_integer' formatter.

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