You are here

public function Range::form in YAML Form 8

Gets the actual configuration form 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 form without any default values..

Overrides NumericBase::form

1 call to Range::form()
YamlFormRating::form in src/Plugin/YamlFormElement/YamlFormRating.php
Gets the actual configuration form array to be built.
1 method overrides Range::form()
YamlFormRating::form in src/Plugin/YamlFormElement/YamlFormRating.php
Gets the actual configuration form array to be built.

File

src/Plugin/YamlFormElement/Range.php, line 62

Class

Range
Provides a 'range' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['number']['#title'] = $this
    ->t('Range settings');
  $form['number']['range__output'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Output the range's value."),
    '#return_type' => TRUE,
  ];
  $form['number']['range__output_prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Range output prefix'),
    '#description' => $this
      ->t('Text or code that is placed directly in front of the output. This can be used to prefix an output with a constant string. Examples: $, #, -.'),
    '#size' => 10,
    '#states' => [
      'visible' => [
        ':input[name="properties[range__output]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['number']['range__output_suffix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Range output suffix'),
    '#description' => $this
      ->t('Text or code that is placed directly after the output. This can be used to add a unit to an output. Examples: lb, kg, %.'),
    '#size' => 10,
    '#states' => [
      'visible' => [
        ':input[name="properties[range__output]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}