Addresses ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Addresses » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 4.0.0
Addresses service.
An instance of the Addresses service is globally accessible in Craft via Craft::$app->addresses
.
Public Properties ​
Property | Description |
---|---|
addressFormatRepository | \CommerceGuys\Addressing\AddressFormat\AddressFormatRepository |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
countryList | array |
countryRepository | \CommerceGuys\Addressing\Country\CountryRepository |
formatter | \CommerceGuys\Addressing\Formatter\FormatterInterface , null – The default address formatter used by formatAddress() |
layout | craft\models\FieldLayout |
subdivisionRepository | craft\addresses\SubdivisionRepository |
addressFormatRepository
​
- Type
\CommerceGuys\Addressing\AddressFormat\AddressFormatRepository
- Default value
null
countryList
​
- Type
- array
- Default value
null
- Access
- Read-only
- Since
- 4.13.0
countryRepository
​
- Type
\CommerceGuys\Addressing\Country\CountryRepository
- Default value
null
formatter
​
- Type
\CommerceGuys\Addressing\Formatter\FormatterInterface
, null- Default value
null
- Since
- 4.5.0
The default address formatter used by formatAddress()
layout
​
- Type
- craft\models\FieldLayout
- Default value
null
- Access
- Read-only
subdivisionRepository
​
- Type
- craft\addresses\SubdivisionRepository
- Default value
null
Public Methods ​
Method | Description |
---|---|
__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. |
getCountryList() | Returns a list of countries to be used as options for selection. |
getCountryRepository() | |
getDependentLocalityTypeLabel() | |
getFieldLabel() | Returns the user-facing label for an address field, for a given country code. |
getLayout() | Returns the address field layout. |
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. |
saveLayout() | Save the address field layout |
trigger() | Triggers an event. |
defineAddressSubdivisions()
​
- Since
- 4.5.0
Returns subdivisions for a field based on its parents.
Arguments ​
Returns ​
formatAddress()
​
Formats the address model into the correct sequence and format in HTML.
Arguments ​
$address
(craft\elements\Address)$options
(array)$formatter
(\CommerceGuys\Addressing\Formatter\FormatterInterface
, null)
Returns ​
getAddressFormatRepository()
​
Returns ​
\CommerceGuys\Addressing\AddressFormat\AddressFormatRepository
getAdministrativeAreaTypeLabel()
​
Arguments ​
Returns ​
getCountryList()
​
- Since
- 4.13.0
Returns a list of countries to be used as options for selection.
Arguments ​
Returns ​
getCountryRepository()
​
Returns ​
\CommerceGuys\Addressing\Country\CountryRepository
getDependentLocalityTypeLabel()
​
Arguments ​
Returns ​
getFieldLabel()
​
- Since
- 4.3.0
Returns the user-facing label for an address field, for a given country code.
Arguments ​
$field
(string) – One of the\CommerceGuys\Addressing\AddressFormat\AddressField
class constants$countryCode
(string)
Returns ​
getLayout()
​
Returns the address field layout.
Returns ​
getLocalityTypeLabel()
​
Arguments ​
Returns ​
getPostalCodeTypeLabel()
​
Arguments ​
Returns ​
getSubdivisionRepository()
​
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\AddressField
View source
Arguments ​
$countryCode
(string)
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\AddressField
View source
Arguments ​
$countryCode
(string)
Returns ​
string[]
handleChangedAddressFieldLayout()
​
Handle address field layout changes.
Arguments ​
$event
(craft\events\ConfigEvent)
init()
​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
saveLayout()
​
Save the address field layout
Arguments ​
$layout
(craft\models\FieldLayout)$runValidation
(boolean) – Whether the layout should be validated
Returns ​
Events ​
EVENT_DEFINE_ADDRESS_COUNTRIES ​
- Type
- craft\events\DefineAddressCountriesEvent
- Since
- 4.13.0
The event that is triggered when defining country options for an address.
This event is primarily used to modify the list of countries that are available for selection. You can also use the event to add additional countries to the list, however, this will require you to use dependency injection to override the Addresses::getCountryRepository()
method and provide your own CountryRepository
instance.
See also getCountryList()
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()