You are here

protected function WebformName::formatTextItemValue in Webform 6.x

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

Format composite element value into lines of text.

Parameters

array $element: An element.

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

array $options: An array of options.

Return value

array Composite element values converted into lines of text.

Overrides WebformCompositeBase::formatTextItemValue

1 call to WebformName::formatTextItemValue()
WebformName::formatHtmlItemValue in src/Plugin/WebformElement/WebformName.php
Format composite element value into lines of text.

File

src/Plugin/WebformElement/WebformName.php, line 33

Class

WebformName
Provides a 'name' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $name_parts = [];
  $composite_elements = $this
    ->getCompositeElements();
  foreach (Element::children($composite_elements) as $name_part) {
    if (!empty($value[$name_part])) {
      $delimiter = in_array($name_part, [
        'suffix',
        'degree',
      ]) ? ', ' : ' ';
      $name_parts[] = $delimiter . $value[$name_part];
    }
  }
  return [
    'name' => trim(implode('', $name_parts)),
  ];
}