You are here

protected function ContainerBase::formatTextItem in Webform 6.x

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

Class

ContainerBase
Provides a base 'container' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {

  /** @var \Drupal\webform\WebformSubmissionViewBuilderInterface $view_builder */
  $view_builder = $this->entityTypeManager
    ->getViewBuilder('webform_submission');
  $children = $view_builder
    ->buildElements($element, $webform_submission, $options, 'text');
  if (empty($children)) {
    return [];
  }
  $build = [];
  if (!empty($element['#title'])) {
    $build['title'] = [
      '#markup' => $element['#title'],
      '#suffix' => PHP_EOL,
    ];
    $build['divider'] = [
      '#markup' => str_repeat('-', mb_strlen($element['#title'])),
      '#suffix' => PHP_EOL,
    ];
  }
  $build['children'] = $children;
  return $build;
}