You are here

protected function TextFormat::formatTextItem in Webform 6.x

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

Format an element's value as text.

Parameters

array $element: An element.

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

array $options: An array of options.

Return value

string The element's value formatted as text.

Overrides WebformElementBase::formatTextItem

See also

_webform_token_get_submission_value()

File

src/Plugin/WebformElement/TextFormat.php, line 241

Class

TextFormat
Provides a 'text_format' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $format = isset($value['format']) ? $value['format'] : $this
    ->getItemFormat($element);
  $value = isset($value['value']) ? $value['value'] : $value;
  switch ($format) {
    case 'raw':
      return $value;
    case 'value':
    default:
      $html = $this
        ->formatHtml($element, $webform_submission);

      // Convert any HTML to plain-text.
      $html = MailFormatHelper::htmlToText($html);

      // Wrap the mail body for sending.
      $html = MailFormatHelper::wrapMail($html);
      return $html;
  }
}