You are here

public static function WebformRating::preRenderWebformRating in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformRating.php \Drupal\webform\Element\WebformRating::preRenderWebformRating()

Prepares a #type 'webform_rating' render element for input.html.twig.

Parameters

array $element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #min, #max, #attributes, #step.

Return value

array The $element with prepared variables ready for input.html.twig.

File

src/Element/WebformRating.php, line 58

Class

WebformRating
Provides a webform element for entering a rating.

Namespace

Drupal\webform\Element

Code

public static function preRenderWebformRating(array $element) {
  $element['#attributes']['type'] = 'range';
  $element['#attributes']['class'][] = 'js-webform-visually-hidden';
  Element::setAttributes($element, [
    'id',
    'name',
    'value',
    'step',
    'min',
    'max',
  ]);
  static::setAttributes($element, [
    'form-webform-rating',
  ]);

  // If value is an empty string set it the min.
  if (isset($element['#attributes']['value']) && $element['#attributes']['value'] === '') {
    $element['#attributes']['value'] = $element['#attributes']['min'];
  }
  $element['#children']['rateit'] = static::buildRateIt($element);
  return $element;
}