You are here

public function DecimalFormatter::settingsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 45
Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter.

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'] = array(
    '#type' => 'select',
    '#title' => t('Decimal marker'),
    '#options' => array(
      '.' => t('Decimal point'),
      ',' => t('Comma'),
    ),
    '#default_value' => $this
      ->getSetting('decimal_separator'),
    '#weight' => 5,
  );
  $range = range(0, 10);
  $elements['scale'] = array(
    '#type' => 'select',
    '#title' => t('Scale', array(), array(
      'decimal places',
    )),
    '#options' => array_combine($range, $range),
    '#default_value' => $this
      ->getSetting('scale'),
    '#description' => t('The number of digits to the right of the decimal.'),
    '#weight' => 6,
  );
  return $elements;
}