You are here

public function HighContrastBlock::blockForm in High contrast 8

Returns the configuration form elements specific to this block plugin.

Blocks that need to add form elements to the normal block configuration form should implement this method.

Parameters

array $form: The form definition array for the block configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The renderable form array representing the entire configuration form.

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/HighContrastBlock.php, line 33

Class

HighContrastBlock
Provides a high contrast Block.

Namespace

Drupal\high_contrast\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $config = $this
    ->getConfiguration();
  $widgets_types = [
    'links' => $this
      ->t('Links'),
    'select' => $this
      ->t('Select list'),
    'radios' => $this
      ->t('Radio buttons'),
  ];
  $form['switcher_widget'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Switcher widget'),
    '#default_value' => isset($config['switcher_widget']) ? $config['switcher_widget'] : '',
    '#options' => $widgets_types,
    '#required' => TRUE,
  ];
  $form['high_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('High contrast label'),
    '#default_value' => isset($config['high_label']) ? $config['high_label'] : $this
      ->t('Enable'),
    '#required' => TRUE,
  ];
  $form['normal_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Normal contrast label'),
    '#default_value' => isset($config['normal_label']) ? $config['normal_label'] : $this
      ->t('Disable'),
    '#required' => TRUE,
  ];
  $form['use_ajax'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use AJAX to submit automatically.'),
    '#default_value' => isset($config['use_ajax']) ? $config['use_ajax'] : FALSE,
  ];
  $form['toggle_element'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Toggle switch'),
    '#description' => $this
      ->t('Shows a single link/checkbox instead or two links/radios.'),
    '#default_value' => isset($config['toggle_element']) ? $config['toggle_element'] : FALSE,
  ];
  return $form;
}