You are here

public function ColorFieldWidgetSpectrum::settingsForm in Color Field 8.2

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/ColorFieldWidgetSpectrum.php, line 41

Class

ColorFieldWidgetSpectrum
Plugin implementation of the color_field spectrum widget.

Namespace

Drupal\color_field\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = [];
  $element['show_input'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Input'),
    '#default_value' => $this
      ->getSetting('show_input'),
    '#description' => $this
      ->t('Allow free form typing.'),
  ];
  $element['show_palette'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Palette'),
    '#default_value' => $this
      ->getSetting('show_palette'),
    '#description' => $this
      ->t('Show or hide Palette in Spectrum Widget'),
  ];
  $element['palette'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Color Palette'),
    '#default_value' => $this
      ->getSetting('palette'),
    '#description' => $this
      ->t('Selectable color palette to accompany the Spectrum Widget. Most possible color values will work - including rgba, rgb, hex, web color names, hsl, hsv. Separate values with a comma, and group them with square brackets - ensure one group per line. Ex: <br> ["#fff","#aaa","#f00","#00f"],<br>["#414141","#242424","#0a8db9"]'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][show_palette]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['show_palette_only'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Palette Only'),
    '#default_value' => $this
      ->getSetting('show_palette_only'),
    '#description' => $this
      ->t('Only show the palette in Spectrum Widget and nothing else'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][show_palette]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['show_buttons'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Buttons'),
    '#default_value' => $this
      ->getSetting('show_buttons'),
    '#description' => $this
      ->t('Add Cancel/Confirm Button.'),
  ];
  $element['cancel_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Cancel button text'),
    '#description' => $this
      ->t('Leave empty to stay default.'),
    '#default_value' => $this
      ->getSetting('cancel_text'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][show_buttons]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['choose_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Choose button text'),
    '#description' => $this
      ->t('Leave empty to stay default.'),
    '#default_value' => $this
      ->getSetting('choose_text'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][show_buttons]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['allow_empty'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow Empty'),
    '#default_value' => $this
      ->getSetting('allow_empty'),
    '#description' => $this
      ->t('Allow empty value.'),
  ];
  return $element;
}