You are here

protected function OptionsBase::formatHtmlItem in Webform 6.x

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

1 call to OptionsBase::formatHtmlItem()
WebformImageSelect::formatHtmlItem in modules/webform_image_select/src/Plugin/WebformElement/WebformImageSelect.php
Format an element's value as HTML.
1 method overrides OptionsBase::formatHtmlItem()
WebformImageSelect::formatHtmlItem in modules/webform_image_select/src/Plugin/WebformElement/WebformImageSelect.php
Format an element's value as HTML.

File

src/Plugin/WebformElement/OptionsBase.php, line 321

Class

OptionsBase
Provides a base 'options' 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 'raw':
      return $value;
    case 'description':
      if (isset($element['#options'])) {
        $options_description = $this
          ->hasProperty('options_description_display');
        if ($options_description) {
          $description = WebformOptionsHelper::getOptionDescription($value, $element['#options'], $options_description);
          return [
            '#markup' => $description,
          ];
        }
      }
      return '';
    case 'value':
    default:
      if (isset($element['#options'])) {
        $options_description = $this
          ->hasProperty('options_description_display');
        $value = WebformOptionsHelper::getOptionText($value, $element['#options'], $options_description);
      }
      $build = [
        '#markup' => $value,
      ];
      $options += [
        'prefixing' => TRUE,
      ];
      if ($options['prefixing']) {
        if (isset($element['#field_prefix'])) {
          $build['#prefix'] = $element['#field_prefix'];
        }
        if (isset($element['#field_suffix'])) {
          $build['#suffix'] = $element['#field_suffix'];
        }
      }
      return $build;
  }
}