public static function LabelHelper::getFieldLabels in Address 8
Gets the field labels suitable for the given address format.
Intended to be shown to the end user, they sometimes use a more familiar term than the field name (Company instead of Organization, Contact name instead of Recipient, etc).
Parameters
\CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format: The address format.
Return value
string[] An array of labels, keyed by field.
5 calls to LabelHelper::getFieldLabels()
- Address::addressElements in src/
Element/ Address.php - Builds the format-specific address elements.
- AddressFormatConstraintValidator::addViolation in src/
Plugin/ Validation/ Constraint/ AddressFormatConstraintValidator.php - AdministrativeArea::exposedInfo in src/
Plugin/ views/ filter/ AdministrativeArea.php - Tell the renderer about our exposed form. This only needs to be overridden for particularly complex forms. And maybe not even then.
- ZoneDefaultFormatter::viewElement in src/
Plugin/ Field/ FieldFormatter/ ZoneDefaultFormatter.php - Builds a renderable array for a single zone item.
- ZoneTerritory::buildSubdivisionElements in src/
Element/ ZoneTerritory.php - Builds the subdivision form elements.
File
- src/
LabelHelper.php, line 54
Class
- LabelHelper
- Provides translated labels for the library enums.
Namespace
Drupal\addressCode
public static function getFieldLabels(AddressFormat $address_format) {
$administrative_area_type = $address_format
->getAdministrativeAreaType();
$locality_type = $address_format
->getLocalityType();
$dependent_locality_type = $address_format
->getDependentLocalityType();
$postal_code_type = $address_format
->getPostalCodeType();
return [
AddressField::GIVEN_NAME => t('First name', [], [
'context' => 'Address label',
]),
AddressField::ADDITIONAL_NAME => t('Middle name', [], [
'context' => 'Address label',
]),
AddressField::FAMILY_NAME => t('Last name', [], [
'context' => 'Address label',
]),
AddressField::ORGANIZATION => t('Company', [], [
'context' => 'Address label',
]),
AddressField::ADDRESS_LINE1 => t('Street address', [], [
'context' => 'Address label',
]),
// The address line 2 label is usually shown only to screen-reader users.
AddressField::ADDRESS_LINE2 => t('Street address line 2', [], [
'context' => 'Address label',
]),
AddressField::POSTAL_CODE => self::getPostalCodeLabel($postal_code_type),
// Google's library always labels the sorting code field as "Cedex".
AddressField::SORTING_CODE => t('Cedex', [], [
'context' => 'Address label',
]),
AddressField::DEPENDENT_LOCALITY => self::getDependentLocalityLabel($dependent_locality_type),
AddressField::LOCALITY => self::getLocalityLabel($locality_type),
AddressField::ADMINISTRATIVE_AREA => self::getAdministrativeAreaLabel($administrative_area_type),
];
}