You are here

public function BooleanBase::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/BooleanBase.php \Drupal\webform\Plugin\WebformElement\BooleanBase::form()

Gets the actual configuration webform array to be built.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array An associative array contain the element's configuration webform without any default values.

Overrides WebformElementBase::form

1 call to BooleanBase::form()
Checkbox::form in src/Plugin/WebformElement/Checkbox.php
Gets the actual configuration webform array to be built.
1 method overrides BooleanBase::form()
Checkbox::form in src/Plugin/WebformElement/Checkbox.php
Gets the actual configuration webform array to be built.

File

src/Plugin/WebformElement/BooleanBase.php, line 69

Class

BooleanBase
Provides a base 'boolean' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  // Add return value to default value details.
  $form['default']['#title'] = $this
    ->t('Return/default value');
  $form['default']['return_value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Return value'),
    '#description' => $this
      ->t('The return value is what is submitted to the server and stored in the database when the element is checked. The default value and recommended return value is a TRUE boolean value.') . '<br/><br/>' . $this
      ->t('<strong>The return value should only be customized when an external system or service expects a custom string value. (i.e. yes, checked, accepted, etc…)</strong>'),
    '#weight' => -20,
  ];

  // Change default value to select boolean.
  $form['default']['default_value'] = [
    '#title' => $this
      ->t('Default value'),
    '#type' => 'select',
    '#options' => [
      0 => $this
        ->t('Unchecked'),
      1 => $this
        ->t('Checked'),
    ],
  ];
  return $form;
}