RangeIntegerFormatter.php in Range 8
File
src/Plugin/Field/FieldFormatter/RangeIntegerFormatter.php
View source
<?php
namespace Drupal\range\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
class RangeIntegerFormatter extends RangeFormatterBase {
public static function defaultSettings() {
return [
'thousand_separator' => '',
] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$options = [
'' => $this
->t('- None -'),
'.' => $this
->t('Decimal point'),
',' => $this
->t('Comma'),
' ' => $this
->t('Space'),
chr(8201) => $this
->t('Thin space'),
"'" => $this
->t('Apostrophe'),
];
$elements['thousand_separator'] = [
'#type' => 'select',
'#title' => $this
->t('Thousand marker'),
'#options' => $options,
'#default_value' => $this
->getSetting('thousand_separator'),
'#weight' => 5,
];
return $elements;
}
protected function formatNumber($number) {
return number_format($number, 0, '', $this
->getSetting('thousand_separator'));
}
}