Same name and namespace in other branches
  1. 8.x-2.x src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php \Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterSwatch::settingsForm() 1 comment

File

src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php, line 32

Class

ColorFieldFormatterSwatch
Plugin implementation of the color_field swatch formatter.

Namespace

Drupal\color_field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) : array {
    $opacity = $this->getFieldSetting('opacity');
    $elements = [];
    $elements['shape'] = [
        '#type' => 'select',
        '#title' => $this->t('Shape'),
        '#options' => $this->getShape(),
        '#default_value' => $this->getSetting('shape'),
        '#description' => '',
    ];
    $elements['width'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Width'),
        '#default_value' => $this->getSetting('width'),
        '#min' => 1,
        '#description' => $this->t('Defaults to pixels (px) if a number is entered, otherwise, you can enter any unit (ie %, em, vw)'),
    ];
    $elements['height'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Height'),
        '#default_value' => $this->getSetting('height'),
        '#min' => 1,
        '#description' => $this->t('Defaults to pixels (px) if a number is entered, otherwise, you can enter any unit (ie %, em, vh)'),
    ];
    if ($opacity) {
        $elements['opacity'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Display opacity'),
            '#default_value' => $this->getSetting('opacity'),
        ];
    }
    $elements['data_attribute'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Use HTML5 data attribute'),
        '#description' => $this->t('Render a data-color HTML 5 data attribute to allow css selectors based on color'),
        '#default_value' => $this->getSetting('data_attribute'),
    ];
    return $elements;
}