WebformName.php in Webform 8.5
File
src/Plugin/WebformElement/WebformName.php
View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Render\Element;
use Drupal\webform\WebformSubmissionInterface;
class WebformName extends WebformCompositeBase {
protected function formatHtmlItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
return $this
->formatTextItemValue($element, $webform_submission, $options);
}
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)),
];
}
}