class AddressFormat (View source)

Properties

protected Text $text
protected FormatterInterface $formatter
protected AddressFormatRepositoryInterface $addressFormatRepository
protected array $options

Options that control the address formatting.

Methods

__construct(Text $text)

The constructor for the service.

setOptions(array $options)

Set the options that control how the address will be rendered. These can be passed to the underlying formatter class.

string
format(array $addressData, string $format = 'html', string|null $locale = null)

Formats a local concrete5 address lines array with the underlying address formatting library.

array
getCountryAddressUsedFields(string $code)

Gets an array of the used local address format keys, i.e. which address lines are used for the country.

array
getCountryAddressRequiredFields(string $code)

Gets an array of the required local address format keys, i.e. which address lines are required for the country.

string
convertLocale(string $locale)

Converts the passed locale to the format expected by the underlying address formatting library.

array
convertFormat(array $sourceFormat)

Converts the underlying address format field array to the "local" format better understood within the concrete5 context.

AddressFormat
getCountryAddressFormat(string $code)

Fetches the country's address format from the address format repository.

string
formatWithoutCountry(array $addressData, string $format = 'html')

This is used only used when no country value is provided. Otherwise formatting is handled by the underlying address formatting library.

Details

__construct(Text $text)

The constructor for the service.

Parameters

Text $text

the concrete5 text service

setOptions(array $options)

Set the options that control how the address will be rendered. These can be passed to the underlying formatter class.

Parameters

array $options

the options

string format(array $addressData, string $format = 'html', string|null $locale = null)

Formats a local concrete5 address lines array with the underlying address formatting library.

The options that can be passed to the formatter in the array of the fourth argument:

  • subdivision_names - Defines whether the subdivision names are printed to the output instead of their codes. Default: true.
  • subdivision_translations - Defines whether the subdivision names are translated to the given locale if translations are available. Otherwise the will be printed out in their default locale. Default: true.

Parameters

array $addressData

an array containing the keys and values for all address lines

string $format

the format of the output value, either 'html' (default) or 'text'

string|null $locale

the locale to be used to translate the country name and possibly the state/province name in case the configuration is set to do so

Return Value

string

the formatted address string

array getCountryAddressUsedFields(string $code)

Gets an array of the used local address format keys, i.e. which address lines are used for the country.

Parameters

string $code

a country code

Return Value

array

an array containing the address line keys

array getCountryAddressRequiredFields(string $code)

Gets an array of the required local address format keys, i.e. which address lines are required for the country.

Parameters

string $code

a country code

Return Value

array

an array containing the address line keys

protected string convertLocale(string $locale)

Converts the passed locale to the format expected by the underlying address formatting library.

Parameters

string $locale

the locale in the concrete5 format

Return Value

string

the locale in the address formatting library format

protected array convertFormat(array $sourceFormat)

Converts the underlying address format field array to the "local" format better understood within the concrete5 context.

Parameters

array $sourceFormat

an array of the field definitions of the underyling address format repository

Return Value

array

an array of the local address format keys

protected AddressFormat getCountryAddressFormat(string $code)

Fetches the country's address format from the address format repository.

Parameters

string $code

the country code

Return Value

AddressFormat

the address format for the country

protected string formatWithoutCountry(array $addressData, string $format = 'html')

This is used only used when no country value is provided. Otherwise formatting is handled by the underlying address formatting library.

Therefore, this does not have to care about the country specific formatting as there is no country information available.

Parameters

array $addressData

the address data to print out

string $format

the display format, 'html' (default) or 'text'

Return Value

string

a text representation of the address