protected function WebformContact::formatTextItemValue in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformContact.php \Drupal\webform\Plugin\WebformElement\WebformContact::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 WebformContact::formatTextItemValue()
- WebformContact::formatHtmlItemValue in src/
Plugin/ WebformElement/ WebformContact.php - Format composite element value into lines of text.
File
- src/
Plugin/ WebformElement/ WebformContact.php, line 57
Class
- WebformContact
- Provides a 'contact' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
$location = '';
if (!empty($value['city'])) {
$location .= $value['city'];
}
if (!empty($value['state_province'])) {
$location .= $location ? ', ' : '';
$location .= $value['state_province'];
}
if (!empty($value['postal_code'])) {
$location .= $location ? '. ' : '';
$location .= $value['postal_code'];
}
$lines = [];
if (!empty($value['name'])) {
$lines['name'] = $value['name'];
}
if (!empty($value['company'])) {
$lines['company'] = $value['company'];
}
if (!empty($value['address'])) {
$lines['address'] = $value['address'];
}
if (!empty($value['address_2'])) {
$lines['address_2'] = $value['address_2'];
}
if ($location) {
$lines['location'] = $location;
}
if (!empty($value['country'])) {
$lines['country'] = $value['country'];
}
if (!empty($value['email'])) {
$lines['email'] = $value['email'];
}
if (!empty($value['phone'])) {
$lines['phone'] = $value['phone'];
}
return $lines;
}