Skip to content
Snippets Groups Projects
Commit e66a6335 authored by Eric Bremner's avatar Eric Bremner Committed by Kevin Paxman
Browse files

ISTWCMS-4947: ensure that location address and map either has values or null

parent 3a62c0d0
No related branches found
No related tags found
1 merge request!127ISTWCMS-4947: ensure that location address and map either has values or null
......@@ -316,7 +316,36 @@ class UWService implements UWServiceInterface {
break;
case 'address':
$node_data['address'] = $node->$data->getValue()[0];
// Set the address initially to null, if there are
// address values, then will be replaced.
$node_data['address'] = NULL;
// Get the address value. There will always be a
// country code and administrative area, so we will
// have to check that there are at least values in
// address that we are using.
$address = $node->$data->getValue()[0];
// Values that we are looking for so that the address
// can be displayed. If there is at least a value in
// this list, we display the address.
$address_values = [
'locality',
'postal_code',
'address_line1',
'address_line2',
];
// Step through each of the address values and check
// if there is a value in the field, if there is
// set the node data variable and exit the loop to
// save computational time.
foreach ($address_values as $address_value) {
if ($address[$address_value]) {
$node_data['address'] = $address;
break;
}
}
break;
case 'author':
......@@ -357,11 +386,18 @@ class UWService implements UWServiceInterface {
break;
case 'map':
$display = [
'type' => 'leaflet_formatter_default',
'label' => 'visually_hidden',
];
$node_data['map'] = $node->$data->view($display);
// Set the map initially to null, if there are
// coordinates, then will be replaced.
$node_data['map'] = NULL;
// If there are coordinates, set the map.
if ($node->$data->getValue()) {
$display = [
'type' => 'leaflet_formatter_default',
'label' => 'visually_hidden',
];
$node_data['map'] = $node->$data->view($display);
}
break;
case 'sources':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment