class Formatter extends DefaultFormatter (View source)

Properties

protected array $defaultOptions

The default options.

Methods

array
buildView(AddressInterface $address, AddressFormat $addressFormat, array $options)

Customized method to get the administrative area's full name for US where they are stored as codes. Both formats work for mail but this is done to preserve backwards compatibility for c5 older versions which print out the state's full name in the address.

array
getSubdivisionValuesWithNames(AddressInterface $address, AddressFormat $addressFormat)

Modified version of DefaultFormatter::getValues().

string|null
getSubdivisionNameValue(AddressInterface $address, Subdivision $subdivision)

Gets the subdivision's name value.

Details

protected array buildView(AddressInterface $address, AddressFormat $addressFormat, array $options)

Customized method to get the administrative area's full name for US where they are stored as codes. Both formats work for mail but this is done to preserve backwards compatibility for c5 older versions which print out the state's full name in the address.

In addition to the default formatter, this adds the following options with the following possibilities:

  • subdivision_names - Return the subdivision names in the return array. By default these are with the default locale as defined for the country for which the subdivisions belong to.
    • Type: boolean
    • Default: true

Since the subdivisions can be translated for each country, this modification only applies in case the 'locale' option has the English language.

{@inheritdoc}

Parameters

AddressInterface $address
AddressFormat $addressFormat
array $options

Return Value

array

protected array getSubdivisionValuesWithNames(AddressInterface $address, AddressFormat $addressFormat)

Modified version of DefaultFormatter::getValues().

This only gets the subdivision values and possibly converts the normally returned codes to subdivision names.

Parameters

AddressInterface $address

the address for which to fetch the subdivisions

AddressFormat $addressFormat

the address format object defining the used subdivision fields

Return Value

array

an array containing the keys of the subdivision fields and their corresponding values

protected string|null getSubdivisionNameValue(AddressInterface $address, Subdivision $subdivision)

Gets the subdivision's name value.

Parameters

AddressInterface $address

the address for which to get the name

Subdivision $subdivision

the subdivision's code to get the name for

Return Value

string|null

a text representation of the subdivision's name or null if a corresponding text representation does not exist