You are here

protected function WebformCompositeBase::formatCompositeTextItems in Webform 6.x

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

Format a composite as a list of plain text 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 plain text items.

2 calls to WebformCompositeBase::formatCompositeTextItems()
WebformCompositeBase::formatTextItem in src/Plugin/WebformElement/WebformCompositeBase.php
Format an element's value as text.
WebformCompositeBase::formatTextItemValue in src/Plugin/WebformElement/WebformCompositeBase.php
Format composite element value into lines of text.

File

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

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatCompositeTextItems(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
      ->formatCompositeText($element, $webform_submission, [
      'composite_key' => $composite_key,
    ] + $options);
    if (is_array($composite_value)) {
      $composite_value = $this->renderer
        ->renderPlain($composite_value);
    }
    if ($composite_value !== '') {
      $items[$composite_key] = "{$composite_title}: {$composite_value}";
    }
  }
  return $items;
}