protected function WebformAddress::formatTextItemValue in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformAddress.php \Drupal\webform\Plugin\WebformElement\WebformAddress::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 WebformAddress::formatTextItemValue()
- WebformAddress::formatHtmlItemValue in src/
Plugin/ WebformElement/ WebformAddress.php - Format composite element value into lines of text.
File
- src/
Plugin/ WebformElement/ WebformAddress.php, line 39
Class
- WebformAddress
- Provides an 'address' 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['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'];
}
return $lines;
}