protected static function ZoneTerritory::buildPostalCodeElements in Address 8
Builds the postal code form elements.
Parameters
array $element: The existing form element array.
array $value: The element value.
\CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format: The address format for the selected country.
Return value
array The form with the added postal code elements.
1 call to ZoneTerritory::buildPostalCodeElements()
- ZoneTerritory::processTerritory in src/
Element/ ZoneTerritory.php - Processes the zone territory form element.
File
- src/
Element/ ZoneTerritory.php, line 234
Class
- ZoneTerritory
- Provides a zone territory form element.
Namespace
Drupal\address\ElementCode
protected static function buildPostalCodeElements(array $element, array $value, AddressFormat $address_format) {
if (!in_array(AddressField::POSTAL_CODE, $address_format
->getUsedFields())) {
// The address format doesn't use a postal code field.
return $element;
}
$element['limit_by_postal_code'] = [
'#type' => 'checkbox',
'#title' => t('Limit by postal code'),
'#default_value' => !empty($value['included_postal_codes']) || !empty($value['excluded_postal_codes']),
];
$checkbox_parents = array_merge($element['#parents'], [
'limit_by_postal_code',
]);
$checkbox_path = array_shift($checkbox_parents);
$checkbox_path .= '[' . implode('][', $checkbox_parents) . ']';
$element['included_postal_codes'] = [
'#type' => 'textarea',
'#title' => t('Included postal codes'),
'#description' => t('A regular expression ("/(35|38)[0-9]{3}/") or comma-separated list, including ranges ("98, 100:200")'),
'#default_value' => $value['included_postal_codes'],
'#rows' => 1,
'#states' => [
'visible' => [
':input[name="' . $checkbox_path . '"]' => [
'checked' => TRUE,
],
],
],
];
$element['excluded_postal_codes'] = [
'#type' => 'textarea',
'#title' => t('Excluded postal codes'),
'#description' => t('A regular expression ("/(35|38)[0-9]{3}/") or comma-separated list, including ranges ("98, 100:200")'),
'#default_value' => $value['excluded_postal_codes'],
'#rows' => 1,
'#states' => [
'visible' => [
':input[name="' . $checkbox_path . '"]' => [
'checked' => TRUE,
],
],
],
];
return $element;
}