You are here

public function FractionDecimalFormatter::settingsForm in Fraction 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/FractionDecimalFormatter.php \Drupal\fraction\Plugin\Field\FieldFormatter\FractionDecimalFormatter::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 FractionFormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/FractionDecimalFormatter.php, line 34

Class

FractionDecimalFormatter
Plugin implementation of the 'fraction_decimal' formatter.

Namespace

Drupal\fraction\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);

  // Decimal precision.
  $elements['precision'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Decimal precision'),
    '#description' => $this
      ->t('Specify the number of digits after the decimal place to display. When "Auto precision" is enabled, this value essentially becomes a minimum fallback precision.'),
    '#default_value' => $this
      ->getSetting('precision'),
    '#required' => TRUE,
    '#weight' => 0,
  ];

  // Auto precision.
  $elements['auto_precision'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Auto precision'),
    '#description' => $this
      ->t('Automatically determine the maximum precision if the fraction has a base-10 denominator. For example, 1/100 would have a precision of 2, 1/1000 would have a precision of 3, etc.'),
    '#default_value' => $this
      ->getSetting('auto_precision'),
    '#weight' => 1,
  ];
  return $elements;
}