You are here

protected function Color::formatHtmlItem in Webform 8.5

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

Class

Color
Provides a 'color' 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 '';
  }
  $format = $this
    ->getItemFormat($element);
  switch ($format) {
    case 'swatch':
      if (!in_array('font', WebformHtmlEditor::getAllowedTags())) {
        return $value;
      }
      else {
        return [
          '#type' => 'inline_template',
          '#template' => '<font color="{{ value }}">█</font> {{ value }}',
          '#context' => [
            'value' => $value,
          ],
        ];
      }
    default:
      return parent::formatHtmlItem($element, $webform_submission, $options);
  }
}