You are here

protected function WebformCompositeBase::formatCompositeHtmlItems in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::formatCompositeHtmlItems()

Format a composite as a list of HTML items.

Parameters

array $element: An element.

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

array $options: An array of options.

Return value

array|string A composite as a list of HTML items.

2 calls to WebformCompositeBase::formatCompositeHtmlItems()
WebformCompositeBase::formatHtmlItem in src/Plugin/WebformElement/WebformCompositeBase.php
Format an element's value as HTML.
WebformCompositeBase::formatHtmlItemValue in src/Plugin/WebformElement/WebformCompositeBase.php
Format composite element value into lines of text.

File

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

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatCompositeHtmlItems(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $format = $this
    ->getItemFormat($element);
  $items = [];
  $composite_elements = $this
    ->getInitializedCompositeElement($element);
  foreach (RenderElement::children($composite_elements) as $composite_key) {
    $composite_element = $composite_elements[$composite_key];
    $composite_title = isset($composite_element['#title']) && $format !== 'raw' ? $composite_element['#title'] : $composite_key;
    $composite_value = $this
      ->formatCompositeHtml($element, $webform_submission, [
      'composite_key' => $composite_key,
    ] + $options);
    if ($composite_value !== '') {
      $items[$composite_key] = [
        '#type' => 'inline_template',
        '#template' => '<b>{{ title }}:</b> {{ value }}',
        '#context' => [
          'title' => $composite_title,
          'value' => $composite_value,
        ],
      ];
    }
  }
  return $items;
}