You are here

public function WebformRating::form in Webform 6.x

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

File

src/Plugin/WebformElement/WebformRating.php, line 110

Class

WebformRating
Provides a 'rating' 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('Rating settings');
  $form['number']['star_size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Star size'),
    '#options' => [
      'small' => $this
        ->t('Small (@size)', [
        '@size' => '16px',
      ]),
      'medium' => $this
        ->t('Medium (@size)', [
        '@size' => '24px',
      ]),
      'large' => $this
        ->t('Large (@size)', [
        '@size' => '32px',
      ]),
    ],
    '#required' => TRUE,
  ];
  $form['number']['reset'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show reset button'),
    '#description' => $this
      ->t('If checked, a reset button will be placed before the rating element.'),
    '#return_value' => TRUE,
  ];

  // Only allow a rating element to be required if the min value can be
  // set to 0.
  $form['validation']['required_container']['#states'] = [
    'visible' => [
      ':input[name="properties[min]"]' => [
        'value' => '0',
      ],
    ],
  ];
  return $form;
}