You are here

protected function WebformRating::formatHtmlItem in Webform 6.x

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

Format an element's value as HTML.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

array $options: An array of options.

Return value

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

Overrides WebformElementBase::formatHtmlItem

File

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

Class

WebformRating
Provides a 'rating' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $format = $this
    ->getItemFormat($element);
  switch ($format) {
    case 'star':

      // Always return the raw value when the rating widget is included in an
      // email or PDF.
      if (!empty($options['email']) || !empty($options['pdf'])) {
        return parent::formatTextItem($element, $webform_submission, $options);
      }
      $build = [
        '#value' => $value,
        '#readonly' => TRUE,
      ] + $element;
      return WebformRatingElement::buildRateIt($build);
    default:
      return parent::formatHtmlItem($element, $webform_submission, $options);
  }
}