You are here

protected function WebformCodeMirror::formatHtmlItem in Webform 6.x

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

Class

WebformCodeMirror
Provides a 'webform_codemirror' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  if (empty($value)) {
    return '';
  }
  $element += [
    '#mode' => 'text',
  ];
  $format = $this
    ->getItemFormat($element);
  switch ($format) {
    case 'code':
      return [
        '#theme' => 'webform_codemirror',
        '#code' => $value,
        '#type' => $element['#mode'],
      ];
    default:
      return parent::formatHtmlItem($element, $webform_submission, $options);
  }
}