You are here

protected function WebformCompositeBase::formatHtmlItem in Webform 6.x

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

2 calls to WebformCompositeBase::formatHtmlItem()
Address::formatHtmlItem in src/Plugin/WebformElement/Address.php
Format an element's value as HTML.
WebformLocationGeocomplete::formatHtmlItem in modules/webform_location_geocomplete/src/Plugin/WebformElement/WebformLocationGeocomplete.php
Format an element's value as HTML.
2 methods override WebformCompositeBase::formatHtmlItem()
Address::formatHtmlItem in src/Plugin/WebformElement/Address.php
Format an element's value as HTML.
WebformLocationGeocomplete::formatHtmlItem in modules/webform_location_geocomplete/src/Plugin/WebformElement/WebformLocationGeocomplete.php
Format an element's value as HTML.

File

src/Plugin/WebformElement/WebformCompositeBase.php, line 388

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  if (!$this
    ->hasValue($element, $webform_submission, $options)) {
    return '';
  }
  $format = $this
    ->getItemFormat($element);

  // Handle custom composite html items.
  if ($format === 'custom' && !empty($element['#format_html'])) {
    return $this
      ->formatCustomItem('html', $element, $webform_submission, $options);
  }
  switch ($format) {
    case 'list':
    case 'raw':
      $items = $this
        ->formatCompositeHtmlItems($element, $webform_submission, $options);
      return [
        '#theme' => 'item_list',
        '#items' => $items,
      ];
    default:
      $lines = $this
        ->formatHtmlItemValue($element, $webform_submission, $options);
      if (empty($lines)) {
        return '';
      }
      foreach ($lines as $key => $line) {
        if (is_string($line)) {
          $lines[$key] = [
            '#markup' => $line,
          ];
        }
        $lines[$key]['#suffix'] = '<br />';
      }

      // Remove the <br/> suffix from the last line.
      unset($lines[$key]['#suffix']);
      return $lines;
  }
}