You are here

protected function YamlFormAddress::formatLines in YAML Form 8

Format composite element value into lines of text.

Parameters

array $element: A composite element.

array $value: Composite element values.

Return value

array Composite element values converted into lines of text.

Overrides YamlFormCompositeBase::formatLines

1 call to YamlFormAddress::formatLines()
YamlFormContact::formatLines in src/Plugin/YamlFormElement/YamlFormContact.php
Format composite element value into lines of text.
1 method overrides YamlFormAddress::formatLines()
YamlFormContact::formatLines in src/Plugin/YamlFormElement/YamlFormContact.php
Format composite element value into lines of text.

File

src/Plugin/YamlFormElement/YamlFormAddress.php, line 41

Class

YamlFormAddress
Provides an 'address' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

protected function formatLines(array $element, array $value) {
  $lines = [];
  if (!empty($value['address'])) {
    $lines['address'] = $value['address'];
  }
  if (!empty($value['address_2'])) {
    $lines['address_2'] = $value['address_2'];
  }
  $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'];
  }
  if ($location) {
    $lines['location'] = $location;
  }
  if (!empty($value['country'])) {
    $lines['country'] = $value['country'];
  }
  return $lines;
}