You are here

public function YamlFormRating::formatHtml in YAML Form 8

Format an element's value as HTML.

Parameters

array $element: An element.

array|mixed $value: A value.

array $options: An array of options.

Return value

array|string The element's value formatted as an HTML string or a render array.

Overrides YamlFormElementBase::formatHtml

File

src/Plugin/YamlFormElement/YamlFormRating.php, line 53

Class

YamlFormRating
Provides a 'rating' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatHtml(array &$element, $value, array $options = []) {
  $format = $this
    ->getFormat($element);
  switch ($format) {
    case 'star':

      // Always return the raw value when the rating widget is included in an
      // email.
      if (!empty($options['email'])) {
        return parent::formatText($element, $value, $options);
      }
      $build = [
        '#value' => $value,
        '#readonly' => TRUE,
      ] + $element;
      return YamlFormRatingElement::buildRateIt($build);
    default:
      return parent::formatHtml($element, $value, $options);
  }
}