class NumberDecimalFormatter

Plugin implementation of the 'number_decimal' 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


@Plugin(
  id = "number_decimal",
  module = "number",
  label = @Translation("Default"),
  field_types = {
    "number_decimal",
    "number_float"
  },
  settings = {
    "thousand_separator" = "",
    "decimal_separator" = ".",
    "scale" = "2",
    "prefix_suffix" = "TRUE"
  }
)

Hierarchy

Expanded class hierarchy of NumberDecimalFormatter

File

drupal/core/modules/field/modules/number/lib/Drupal/number/Plugin/field/formatter/NumberDecimalFormatter.php, line 39
Definition of Drupal\number\Plugin\field\formatter\NumberDecimalFormatter.

Namespace

Drupal\number\Plugin\field\formatter
View source
class NumberDecimalFormatter extends DefaultNumberFormatter {

  /**
   * Overrides Drupal\number\Plugin\field\formatter\DefaultNumberFormatter::settingsForm().
   */
  public function settingsForm(array $form, array &$form_state) {
    $elements = parent::settingsForm($form, $form_state);
    $elements['decimal_separator'] = array(
      '#type' => 'select',
      '#title' => t('Decimal marker'),
      '#options' => array(
        '.' => t('Decimal point'),
        ',' => t('Comma'),
      ),
      '#default_value' => $this
        ->getSetting('decimal_separator'),
      'weight' => 5,
    );
    $elements['scale'] = array(
      '#type' => 'select',
      '#title' => t('Scale'),
      '#options' => drupal_map_assoc(range(0, 10)),
      '#default_value' => $this
        ->getSetting('scale'),
      '#description' => t('The number of digits to the right of the decimal.'),
      'weight' => 6,
    );
    return $elements;
  }

  /**
   * Overrides Drupal\number\Plugin\field\formatter\DefaultNumberFormatter::numberFormat().
   */
  protected function numberFormat($number) {
    return number_format($number, $this
      ->getSetting('scale'), $this
      ->getSetting('decimal_separator'), $this
      ->getSetting('thousand_separator'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultNumberFormatter::settingsSummary public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm(). Overrides FormatterBase::settingsSummary
DefaultNumberFormatter::viewElements public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). Overrides FormatterInterface::viewElements
FormatterBase::$field protected property The field definition.
FormatterBase::$instance protected property The field instance definition.
FormatterBase::$label protected property The label display setting.
FormatterBase::$settings protected property The formatter settings. Overrides PluginSettingsBase::$settings
FormatterBase::$viewMode protected property The view mode.
FormatterBase::$weight protected property The formatter weight.
FormatterBase::prepareView public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView(). Overrides FormatterInterface::prepareView 2
FormatterBase::view public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::view(). Overrides FormatterInterface::view
FormatterBase::__construct public function Constructs a FormatterBase object. Overrides PluginBase::__construct
NumberDecimalFormatter::numberFormat protected function Overrides Drupal\number\Plugin\field\formatter\DefaultNumberFormatter::numberFormat(). Overrides DefaultNumberFormatter::numberFormat
NumberDecimalFormatter::settingsForm public function Overrides Drupal\number\Plugin\field\formatter\DefaultNumberFormatter::settingsForm(). Overrides DefaultNumberFormatter::settingsForm
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$discovery protected property The discovery object.
PluginBase::$plugin_id protected property The plugin_id.
PluginBase::getDefinition public function Implements Drupal\Component\Plugin\PluginInterface::getDefinition(). Overrides PluginInspectionInterface::getDefinition
PluginBase::getPluginId public function Implements Drupal\Component\Plugin\PluginInterface::getPluginId(). Overrides PluginInspectionInterface::getPluginId
PluginSettingsBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
PluginSettingsBase::getDefaultSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getDefaultSettings(). Overrides PluginSettingsInterface::getDefaultSettings
PluginSettingsBase::getSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSetting(). Overrides PluginSettingsInterface::getSetting
PluginSettingsBase::getSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSettings(). Overrides PluginSettingsInterface::getSettings
PluginSettingsBase::mergeDefaults protected function Merges default settings values into $settings.
PluginSettingsBase::setSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSetting(). Overrides PluginSettingsInterface::setSetting
PluginSettingsBase::setSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSettings(). Overrides PluginSettingsInterface::setSettings