Skip to content

Commit

Permalink
Merge pull request #10 from asmallwebfirm/fix-missing-city
Browse files Browse the repository at this point in the history
Fix missing localityname (city) field in some situations.
  • Loading branch information
iamEAP committed May 7, 2014
2 parents fe6ec6d + 5846faa commit a4e0b6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scale_addressfield.address.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ function scale_addressfield_override_format(&$format, $address, $context = array
),
'type' => 'setting',
);
$format[$container][$name]['#attributes']['class'][] = $xnal_field;
// Special case for "localityname" because Address Field provides
// "locality" as a class name by default. So, overwrite it entirely.
if ($xnal_field == 'localityname') {
$format[$container][$name]['#attributes']['class'] = array($xnal_field);
}
else {
// Otherwise, just append our class.
$format[$container][$name]['#attributes']['class'][] = $xnal_field;
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions scale_addressfield.test
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ abstract class ScaleAddressfieldWebTestCase extends DrupalWebTestCase {

if ($elements) {
foreach ($elements as $element) {
// Add extra padding (in case the class comes first or last).
$element['class'] = ' ' . $element['class'] . ' ';
if (isset($element['class']) && strpos($element['class'], $class) !== FALSE) {
$has_class = TRUE;
}
Expand Down Expand Up @@ -253,6 +255,10 @@ class ScaleAddressfieldFormRenderTestCase extends ScaleAddressfieldWebTestCase {
}
}

// Ensure the localityname field does not have a "locality" class.
$field = $this->xpath($this->constructFieldXpath('name', $this->fields['localityname']));
$this->assertTrue(strpos('locality ', $field[0]['class']) === FALSE, 'Locality class not found on localityname element.');

// Ensure that the administrative area field is rendered as a textfield.
$this->assertFieldByXpath($this->buildXPathQuery('//input[@name=:name]', array(
':name' => $this->fields['administrativearea'],
Expand Down

0 comments on commit a4e0b6c

Please sign in to comment.