You are here

public function WebformScale::form in Webform 6.x

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

File

src/Plugin/WebformElement/WebformScale.php, line 67

Class

WebformScale
Provides a 'scale' 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('Scale settings');
  $form['number']['number_container']['min']['#min'] = 0;
  $form['number']['number_container']['min']['#step'] = 1;
  $form['number']['number_container']['min']['#required'] = TRUE;
  $form['number']['number_container']['max']['#min'] = 0;
  $form['number']['number_container']['max']['#step'] = 1;
  $form['number']['number_container']['max']['#required'] = TRUE;
  $form['number']['min_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Minimum label'),
    '#description' => $this
      ->t('Label for the minimum value in the scale.'),
  ];
  $form['number']['max_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Maximum label'),
    '#description' => $this
      ->t('Label for the maximum value in the scale.'),
  ];
  $form['number']['scale_container'] = $this
    ->getFormInlineContainer();
  $form['number']['scale_container']['scale_size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Scale size'),
    '#options' => [
      'small' => $this
        ->t('Small (@size)', [
        '@size' => '24px',
      ]),
      'medium' => $this
        ->t('Medium (@size)', [
        '@size' => '36px',
      ]),
      'large' => $this
        ->t('Large (@size)', [
        '@size' => '48px',
      ]),
    ],
    '#required' => TRUE,
  ];
  $form['number']['scale_container']['scale_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Scale type'),
    '#options' => [
      'circle' => $this
        ->t('Circle'),
      'square' => $this
        ->t('Square'),
      'flexbox' => $this
        ->t('Flexbox'),
    ],
    '#required' => TRUE,
  ];
  $form['number']['scale_container']['scale_text'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Scale text'),
    '#options' => [
      'above' => $this
        ->t('Above'),
      'below' => $this
        ->t('Below'),
    ],
    '#required' => TRUE,
  ];
  return $form;
}