This Field Type represents one or multiple countries.
Name | Internal name | Expected input |
---|
Country | ezcountry | array |
Table of contents:
Description
This Field Type makes possible to store and retrieve data representing countries.
Type | Example |
---|
array | Code Block |
---|
language | php |
---|
linenumbers | true |
---|
| array(
"JP" => array(
"Name" => "Japan",
"Alpha2" => "JP",
"Alpha3" => "JPN",
"IDC" => 81
)
); |
|
Note: When you set an array directly on Content field you don't need to provide all this information, the Field Type will assume it is a hash and in this case will accept a simplified structure described below under To / From Hash format.
Validation
This Field Type validates if the multiple countries are allowed by the field definition, and if the Alpha2 is valid according to the countries configured in eZ Platform.
Settings
The field definition of this Field Type can be configured with one option:
Name | Type | Default value | Description |
---|
isMultiple | boolean | false | This setting allows (if true) or denies (if false) the selection of multiple countries. |
Code Block |
---|
language | php |
---|
title | Country FieldType example settings |
---|
linenumbers | true |
---|
|
$settings = array(
"isMultiple" => true
); |
Anchor |
---|
| ToFromHashFormat |
---|
| ToFromHashFormat |
---|
|
To / From Hash format
The format used for serialization is simpler than the full format, this is also available when setting value on the content field, by setting the value to an array instead of the Value object. Example of that shown below:
Code Block |
---|
language | php |
---|
title | Value object content example |
---|
linenumbers | true |
---|
|
$content->fields["countries"] = array( "JP", "NO" ); |
The format used by the toHash method is the Alpha2 value, however the input is capable of accepting either Name, Alpha2 or Alpha3 value as shown below in the Value object section.
Value object
Properties
The Value class of this field type contains the following properties:
Property | Type | Description |
---|
$countries | array[] | This property will be used for the country selection provided as input, as its attributes. |
Code Block |
---|
language | php |
---|
title | Value object content example |
---|
linenumbers | true |
---|
|
$value->countries = array(
"JP" => array(
"Name" => "Japan",
"Alpha2" => "JP",
"Alpha3" => "JPN",
"IDC" => 81
)
) |
Constructor
The Country
\Value
constructor will initialize a new Value object with the value provided. It expects an array as input.
Code Block |
---|
language | php |
---|
title | Constructor example |
---|
linenumbers | true |
---|
|
// Instantiates a Country Value object
$countryValue = new Country\Value(
array(
"JP" => array(
"Name" => "Japan",
"Alpha2" => "JP",
"Alpha3" => "JPN",
"IDC" => 81
)
)
); |