You are here

public static function YamlFormRating::preRenderYamlFormRating in YAML Form 8

Prepares a #type 'yamlform_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/YamlFormRating.php, line 44

Class

YamlFormRating
Provides a form element for entering a rating.

Namespace

Drupal\yamlform\Element

Code

public static function preRenderYamlFormRating($element) {
  $element['#attributes']['type'] = 'range';
  Element::setAttributes($element, [
    'id',
    'name',
    'value',
    'step',
    'min',
    'max',
  ]);
  static::setAttributes($element, [
    'form-yamlform-rating',
  ]);

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