YamlFormAddress.php in YAML Form 8
File
src/Plugin/YamlFormElement/YamlFormAddress.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\Core\Form\FormState;
use Drupal\yamlform\Element\YamlFormAddress as YamlFormAddressElement;
class YamlFormAddress extends YamlFormCompositeBase {
protected function getCompositeElements() {
return YamlFormAddressElement::getCompositeElements();
}
protected function getInitializedCompositeElement(array &$element) {
$form_state = new FormState();
$form_completed = [];
return YamlFormAddressElement::processYamlFormComposite($element, $form_state, $form_completed);
}
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;
}
}