You are here

public function ToggleEditableFormatter::settingsForm in Toggle Editable fields 8

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 FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/ToggleEditableFormatter.php, line 157

Class

ToggleEditableFormatter
Plugin implementation of the 'ranking' formatter.

Namespace

Drupal\toggle_editable_fields\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  parent::settingsForm($form, $form_state);
  $elements['on'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Use custom label for "On state"'),
    '#default_value' => $this
      ->getSetting('on'),
  ];
  $elements['off'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Use custom label for "Off state"'),
    '#default_value' => $this
      ->getSetting('off'),
  ];
  $elements['size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Size of toggle button'),
    '#default_value' => $this
      ->getSetting('size'),
    '#options' => $this
      ->bootstrapToggleSizesOptions(),
  ];
  $elements['onstyle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('On state style of toggle button'),
    '#default_value' => $this
      ->getSetting('onstyle'),
    '#options' => $this
      ->bootstrapToggleStylesOptions(),
  ];
  $elements['offstyle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Off state style of toggle button'),
    '#default_value' => $this
      ->getSetting('offstyle'),
    '#options' => $this
      ->bootstrapToggleStylesOptions(),
  ];
  $elements['height'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Override height of toggle button'),
    '#default_value' => $this
      ->getSetting('height'),
    '#field_suffix' => ' ' . $this
      ->t('pixels'),
    '#min' => 1,
  ];
  $elements['width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Override width of toggle button'),
    '#default_value' => $this
      ->getSetting('width'),
    '#field_suffix' => ' ' . $this
      ->t('pixels'),
    '#min' => 1,
  ];
  return $elements;
}