You are here

public function DecimalFormatter::settingsForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter::settingsForm()

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides NumericFormatterBase::settingsForm

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php, line 40

Class

DecimalFormatter
Plugin implementation of the 'number_decimal' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['decimal_separator'] = [
    '#type' => 'select',
    '#title' => t('Decimal marker'),
    '#options' => [
      '.' => t('Decimal point'),
      ',' => t('Comma'),
    ],
    '#default_value' => $this
      ->getSetting('decimal_separator'),
    '#weight' => 5,
  ];
  $elements['scale'] = [
    '#type' => 'number',
    '#title' => t('Scale', [], [
      'context' => 'decimal places',
    ]),
    '#min' => 0,
    '#max' => 10,
    '#default_value' => $this
      ->getSetting('scale'),
    '#description' => t('The number of digits to the right of the decimal.'),
    '#weight' => 6,
  ];
  return $elements;
}