Same name and namespace in other branches
- 8.x-2.x src/Plugin/Field/FieldWidget/ColorFieldWidgetSpectrum.php \Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldWidgetSpectrum::settingsForm()
Fichier
-
src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetSpectrum.php, line 27
Classe
- ColorFieldWidgetSpectrum
- Plugin implementation of the color_field spectrum widget.
Namespace
Drupal\color_field\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) : array {
$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;
}