You are here

public function FractionDecimalWidget::settingsForm in Fraction 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldWidget/FractionDecimalWidget.php \Drupal\fraction\Plugin\Field\FieldWidget\FractionDecimalWidget::settingsForm()

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.

Overrides WidgetBase::settingsForm

File

src/Plugin/Field/FieldWidget/FractionDecimalWidget.php, line 36

Class

FractionDecimalWidget
Plugin implementation of the 'fraction_decimal' widget.

Namespace

Drupal\fraction\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $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 converting the fraction to a decimal. 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;
}