Skip to content

Addresses

Type
Class
Namespace
craft\services
Inherits
craft\services\Addresses » yii\base\Component » yii\base\BaseObject
Implements
craft\base\FieldLayoutProviderInterface, yii\base\Configurable
Since
4.0.0

Addresses service.

An instance of the Addresses service is globally accessible in Craft via Craft::$app->addresses.

View source

Public Properties

PropertyDescription
addressFormatRepository\CommerceGuys\Addressing\AddressFormat\AddressFormatRepository
behaviorsyii\base\Behavior – List of behaviors attached to this component.
countryRepository\CommerceGuys\Addressing\Country\CountryRepository
fieldLayoutcraft\models\FieldLayout
formatter\CommerceGuys\Addressing\Formatter\FormatterInterface, null – The default address formatter used by formatAddress()
handlestring, null
subdivisionRepositorycraft\addresses\SubdivisionRepository

addressFormatRepository

Type
\CommerceGuys\Addressing\AddressFormat\AddressFormatRepository
Default value
null

View source

countryRepository

Type
\CommerceGuys\Addressing\Country\CountryRepository
Default value
null

View source

fieldLayout

Type
craft\models\FieldLayout
Default value
null
Access
Read-only
Since
5.0.0

View source

formatter

Type
\CommerceGuys\Addressing\Formatter\FormatterInterface, null
Default value
null
Since
4.5.0

The default address formatter used by formatAddress()

View source

handle

Type
string, null
Default value
null
Access
Read-only
Since
5.0.0

View source

subdivisionRepository

Type
craft\addresses\SubdivisionRepository
Default value
null

View source

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
defineAddressSubdivisions()Returns subdivisions for a field based on its parents.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
formatAddress()Formats the address model into the correct sequence and format in HTML.
getAddressFormatRepository()
getAdministrativeAreaTypeLabel()
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getCountryRepository()
getDependentLocalityTypeLabel()
getFieldLabel()Returns the user-facing label for an address field, for a given country code.
getFieldLayout()Returns the field layout defined by this component.
getHandle()Returns the provider’s handle, which could be used to identify custom fields with ambiguous handles.
getLocalityTypeLabel()
getPostalCodeTypeLabel()
getSubdivisionRepository()
getUsedFields()Returns the address fields that are used by a given country code.
getUsedSubdivisionFields()Returns the subdivision address fields that are used by a given country code.
handleChangedAddressFieldLayout()Handle address field layout changes.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
saveFieldLayout()Save the address field layout
trigger()Triggers an event.

defineAddressSubdivisions()

Since
4.5.0

Returns subdivisions for a field based on its parents.

View source

Arguments

Returns

array

formatAddress()

Formats the address model into the correct sequence and format in HTML.

View source

Arguments

Returns

string

getAddressFormatRepository()

View source

Returns

\CommerceGuys\Addressing\AddressFormat\AddressFormatRepository

getAdministrativeAreaTypeLabel()

View source

Arguments

Returns

string

getCountryRepository()

View source

Returns

\CommerceGuys\Addressing\Country\CountryRepository

getDependentLocalityTypeLabel()

View source

Arguments

Returns

string

getFieldLabel()

Since
4.3.0

Returns the user-facing label for an address field, for a given country code.

View source

Arguments

  • $field (string) – One of the \CommerceGuys\Addressing\AddressFormat\AddressField class constants
  • $countryCode (string)

Returns

string

getFieldLayout()

Since
5.0.0

Returns the field layout defined by this component.

View source

Returns

craft\models\FieldLayout

getHandle()

Since
5.0.0

Returns the provider’s handle, which could be used to identify custom fields with ambiguous handles.

View source

Returns

string, null

getLocalityTypeLabel()

View source

Arguments

Returns

string

getPostalCodeTypeLabel()

View source

Arguments

Returns

string

getSubdivisionRepository()

View source

Returns

craft\addresses\SubdivisionRepository

getUsedFields()

Since
4.3.0

Returns the address fields that are used by a given country code.

See also \CommerceGuys\Addressing\AddressFormat\AddressFieldView source

Arguments

Returns

string[]

getUsedSubdivisionFields()

Since
4.3.0

Returns the subdivision address fields that are used by a given country code.

See also \CommerceGuys\Addressing\AddressFormat\AddressFieldView source

Arguments

Returns

string[]

handleChangedAddressFieldLayout()

Handle address field layout changes.

View source

Arguments

init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

saveFieldLayout()

Save the address field layout

View source

Arguments

Returns

boolean

Events

EVENT_DEFINE_ADDRESS_SUBDIVISIONS

Type
craft\events\DefineAddressSubdivisionsEvent
Since
4.5.0

The event that is triggered when defining subdivisions options for an address field for a given country code, and optionally administrativeArea and locality.

See also defineAddressSubdivisions()


EVENT_DEFINE_FIELD_LABEL

Type
craft\events\DefineAddressFieldLabelEvent
Since
4.3.0

The event that is triggered when defining the label of an address field for a given country code.

See also getFieldLabel()


EVENT_DEFINE_USED_FIELDS

Type
craft\events\DefineAddressFieldsEvent
Since
4.3.0

The event that is triggered when defining the address fields that are used by a given country code.

See also getUsedFields()


EVENT_DEFINE_USED_SUBDIVISION_FIELDS

Type
craft\events\DefineAddressFieldsEvent
Since
4.3.0

The event that is triggered when defining the subdivision address fields that are used by a given country code.

See also getUsedSubdivisionFields()