You are here

public function Range::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/Range.php \Drupal\webform\Plugin\WebformElement\Range::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 NumericBase::form

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

File

src/Plugin/WebformElement/Range.php, line 183

Class

Range
Provides a 'range' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['number']['#title'] = $this
    ->t('Range settings');
  $form['output'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Range output settings'),
  ];
  $form['output']['output'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Output the range's value"),
    '#empty_option' => $this
      ->t('- None -'),
    '#options' => [
      'right' => $this
        ->t('Right'),
      'left' => $this
        ->t('Left'),
      'above' => $this
        ->t('Above (Floating)'),
      'below' => $this
        ->t('Below (Floating)'),
    ],
  ];
  $form['output']['output_container'] = $this
    ->getFormInlineContainer() + [
    '#states' => [
      'visible' => [
        ':input[name="properties[output]"]' => [
          '!value' => '',
        ],
      ],
    ],
  ];
  $form['output']['output_container']['output__field_prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('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,
  ];
  $form['output']['output_container']['output__field_suffix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('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,
  ];
  $form['output']['output__attributes'] = [
    '#type' => 'webform_element_attributes',
    '#title' => $this
      ->t('Output'),
    '#classes' => $this->configFactory
      ->get('webform.settings')
      ->get('element.classes'),
    '#states' => [
      'visible' => [
        ':input[name="properties[output]"]' => [
          '!value' => '',
        ],
      ],
    ],
  ];
  return $form;
}