Interface

eZ\Publish\SPI\FieldType\FieldType

interface FieldType

The field type interface which all field types have to implement.

Hashes:

The {@link toHash()} method in this class is meant to generate a simple representation of a value of this field type. Hash does here not refer to MD5 or similar hashing algorithms, but rather to hash-map (associative array) type representation. This representation must be usable, to transfer the value over plain text encoding formats, like e.g. XML. As a result, the returned "hash" must either be a scalar value, a hash array (associative array) a pure numeric array or a nested combination of these. It must by no means contain objects, resources or cyclic references. The corresponding {@link fromHash()} method must convert such a representation back into a value, which is understood by the FieldType.

Methods

string getFieldTypeIdentifier()

Returns the field type identifier for this field type.

string getName(Value $value)

Returns a human readable string representation from the given $value.

mixed getSettingsSchema()

Returns a schema for the settings expected by the FieldType.

mixed getValidatorConfigurationSchema()

Returns a schema for the validator configuration expected by the FieldType.

ValidationError[] validate(FieldDefinition $fieldDef, Value $value)

Validates a field based on the validator configuration in the field definition.

ValidationError[] validateValidatorConfiguration(mixed $validatorConfiguration)

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

applyDefaultValidatorConfiguration(mixed $validatorConfiguration)

Applies the default values to the given $validatorConfiguration of a FieldDefinitionCreateStruct.

ValidationError[] validateFieldSettings(mixed $fieldSettings)

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

applyDefaultSettings(mixed $fieldSettings)

Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.

bool isSearchable()

Indicates if the field type supports indexing and sort keys for searching.

bool isSingular()

Indicates if the field definition of this type can appear only once in the same ContentType.

bool onlyEmptyInstance()

Indicates if the field definition of this type can be added to a ContentType with Content instances.

Value getEmptyValue()

Returns the empty value for this field type.

bool isEmptyValue(Value $value)

Returns if the given $value is considered empty by the field type.

Value acceptValue(mixed $inputValue)

Potentially builds and checks the type and structure of the $inputValue.

Value fromHash(mixed $hash)

Converts an $hash to the Value defined by the field type.

mixed toHash(Value $value)

Converts the given $value into a plain hash format.

array|hash|scalar|null fieldSettingsToHash(mixed $fieldSettings)

Converts the given $fieldSettings to a simple hash format.

mixed fieldSettingsFromHash(array|hash|scalar|null $fieldSettingsHash)

Converts the given $fieldSettingsHash to field settings of the type.

array|hash|scalar|null validatorConfigurationToHash(mixed $validatorConfiguration)

Converts the given $validatorConfiguration to a simple hash format.

mixed validatorConfigurationFromHash(array|hash|scalar|null $validatorConfigurationHash)

Converts the given $validatorConfigurationHash to a validator configuration of the type.

FieldValue toPersistenceValue(Value $value)

Converts a $value to a persistence value.

Value fromPersistenceValue(FieldValue $fieldValue)

Converts a persistence $value to a Value.

array getRelations(Value $value)

Returns relation data extracted from value.

Details

at line 44
public string getFieldTypeIdentifier()

Returns the field type identifier for this field type.

This identifier should be globally unique and the implementer of a FieldType must take care for the uniqueness. It is therefore recommended to prefix the field-type identifier by a unique string that identifies the implementer. A good identifier could for example take your companies main domain name as a prefix in reverse order.

Return Value

string

at line 59
public string getName(Value $value)

Returns a human readable string representation from the given $value.

It will be used to generate content name and url alias if current field is designated to be used in the content name/urlAlias pattern.

The used $value can be assumed to be already accepted by {@link * acceptValue()}.

Parameters

Value $value

Return Value

string

at line 80
public mixed getSettingsSchema()

Returns a schema for the settings expected by the FieldType.

Returns an arbitrary value, representing a schema for the settings of the FieldType.

Explanation: There are no possible generic schemas for defining settings input, which is why no schema for the return value of this method is defined. It is up to the implementer to define and document a schema for the return value and document it. In addition, it is necessary that all consumers of this interface (e.g. Public API, REST API, GUIs, ...) provide plugin mechanisms to hook adapters for the specific FieldType into. These adapters then need to be either shipped with the FieldType or need to be implemented by a third party. If there is no adapter available for a specific FieldType, it will not be usable with the consumer.

Return Value

mixed

at line 121
public mixed getValidatorConfigurationSchema()

Returns a schema for the validator configuration expected by the FieldType.

Returns an arbitrary value, representing a schema for the validator configuration of the FieldType.

Explanation: There are no possible generic schemas for defining settings input, which is why no schema for the return value of this method is defined. It is up to the implementer to define and document a schema for the return value and document it. In addition, it is necessary that all consumers of this interface (e.g. Public API, REST API, GUIs, ...) provide plugin mechanisms to hook adapters for the specific FieldType into. These adapters then need to be either shipped with the FieldType or need to be implemented by a third party. If there is no adapter available for a specific FieldType, it will not be usable with the consumer.

Best practice:

It is considered best practice to return a hash map, which contains rudimentary settings structures, like e.g. for the "ezstring" FieldType

array( 'stringLength' => array( 'minStringLength' => array( 'type' => 'int', 'default' => 0, ), 'maxStringLength' => array( 'type' => 'int' 'default' => null, ) ), );

Return Value

mixed

at line 133
public ValidationError[] validate(FieldDefinition $fieldDef, Value $value)

Validates a field based on the validator configuration in the field definition.

Parameters

FieldDefinition $fieldDef The field definition of the field
Value $value The field value for which an action is performed

Return Value

ValidationError[]

Exceptions

InvalidArgumentException

at line 146
public ValidationError[] validateValidatorConfiguration(mixed $validatorConfiguration)

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

This methods determines if the given $validatorConfiguration is structurally correct and complies to the validator configuration schema returned by {@link getValidatorConfigurationSchema()}.

Parameters

mixed $validatorConfiguration

Return Value

ValidationError[]

at line 155
public applyDefaultValidatorConfiguration(mixed $validatorConfiguration)

Applies the default values to the given $validatorConfiguration of a FieldDefinitionCreateStruct.

Parameters

mixed $validatorConfiguration

Exceptions

InvalidArgumentException

at line 167
public ValidationError[] validateFieldSettings(mixed $fieldSettings)

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

This methods determines if the given $fieldSettings are structurally correct and comply to the settings schema returned by {@link * getSettingsSchema()}.

Parameters

mixed $fieldSettings

Return Value

ValidationError[]

at line 176
public applyDefaultSettings(mixed $fieldSettings)

Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.

Parameters

mixed $fieldSettings

Exceptions

InvalidArgumentException

at line 183
public bool isSearchable()

Indicates if the field type supports indexing and sort keys for searching.

Return Value

bool

at line 190
public bool isSingular()

Indicates if the field definition of this type can appear only once in the same ContentType.

Return Value

bool

at line 197
public bool onlyEmptyInstance()

Indicates if the field definition of this type can be added to a ContentType with Content instances.

Return Value

bool

at line 209
public Value getEmptyValue()

Returns the empty value for this field type.

This value will be used, if no value was provided for a field of this type and no default value was specified in the field definition. It is also used to determine that a user intentionally (or unintentionally) did not set a non-empty value.

Return Value

Value

at line 222
public bool isEmptyValue(Value $value)

Returns if the given $value is considered empty by the field type.

Usually, only the value returned by {@link getEmptyValue()} is considered empty. The given $value can be safely assumed to have already been processed by {@link acceptValue()}.

Parameters

Value $value

Return Value

bool

at line 245
public Value acceptValue(mixed $inputValue)

Potentially builds and checks the type and structure of the $inputValue.

This method first inspects $inputValue and convert it into a dedicated value object.

After that, the value is checked for structural validity. Note that this does not include validation after the rules from validators, but only plausibility checks for the general data format.

Note that this method must also cope with the empty value for the field type as e.g. returned by {@link getEmptyValue()}.

Parameters

mixed $inputValue

Return Value

Value The potentially converted and structurally plausible value.

Exceptions

InvalidArgumentException if the parameter is not of the supported value sub type
InvalidArgumentException if the value does not match the expected structure

at line 259
public Value fromHash(mixed $hash)

Converts an $hash to the Value defined by the field type.

This is the reverse operation to {@link toHash()}. At least the hash format generated by {@link toHash()} must be converted in reverse. Additional formats might be supported in the rare case that this is necessary. See the class description for more details on a hash format.

Parameters

mixed $hash

Return Value

Value

at line 273
public mixed toHash(Value $value)

Converts the given $value into a plain hash format.

Converts the given $value into a plain hash format, which can be used to transfer the value through plain text formats, e.g. XML, which do not support complex structures like objects. See the class level doc block for additional information. See the class description for more details on a hash format.

Parameters

Value $value

Return Value

mixed

at line 284
public array|hash|scalar|null fieldSettingsToHash(mixed $fieldSettings)

Converts the given $fieldSettings to a simple hash format.

See the class description for more details on a hash format.

Parameters

mixed $fieldSettings

Return Value

array|hash|scalar|null

at line 296
public mixed fieldSettingsFromHash(array|hash|scalar|null $fieldSettingsHash)

Converts the given $fieldSettingsHash to field settings of the type.

This is the reverse operation of {@link fieldSettingsToHash()}. See the class description for more details on a hash format.

Parameters

array|hash|scalar|null $fieldSettingsHash

Return Value

mixed

at line 307
public array|hash|scalar|null validatorConfigurationToHash(mixed $validatorConfiguration)

Converts the given $validatorConfiguration to a simple hash format.

See the class description for more details on a hash format.

Parameters

mixed $validatorConfiguration

Return Value

array|hash|scalar|null

at line 319
public mixed validatorConfigurationFromHash(array|hash|scalar|null $validatorConfigurationHash)

Converts the given $validatorConfigurationHash to a validator configuration of the type.

See the class description for more details on a hash format.

Parameters

array|hash|scalar|null $validatorConfigurationHash

Return Value

mixed

at line 343
public FieldValue toPersistenceValue(Value $value)

Converts a $value to a persistence value.

In this method the field type puts the data which is stored in the field of content in the repository into the property FieldValue::data. The format of $data is a primitive, an array (map) or an object, which is then canonically converted to e.g. json/xml structures by future storage engines without further conversions. For mapping the $data to the legacy database an appropriate Converter (implementing eZ\Publish\Core\Persistence\Legacy\FieldValue\Converter) has implemented for the field type. Note: $data should only hold data which is actually stored in the field. It must not hold data which is stored externally.

The $externalData property in the FieldValue is used for storing data externally by the FieldStorage interface method storeFieldData.

The FieldValuer::sortKey is build by the field type for using by sort operations.

Parameters

Value $value The value of the field type

Return Value

FieldValue the value processed by the storage engine

See also

\eZ\Publish\SPI\Persistence\Content\FieldValue

at line 354
public Value fromPersistenceValue(FieldValue $fieldValue)

Converts a persistence $value to a Value.

This method builds a field type value from the $data and $externalData properties.

Parameters

FieldValue $fieldValue

Return Value

Value

at line 381
public array getRelations(Value $value)

Returns relation data extracted from value.

Not intended for \eZ\Publish\API\Repository\Values\Content\Relation::COMMON type relations, there is an API for handling those.

Parameters

Value $value

Return Value

array Hash with relation type as key and array of destination content ids as value. Example: array( \eZ\Publish\API\Repository\Values\Content\Relation::LINK => array( "contentIds" => array( 12, 13, 14 ), "locationIds" => array( 24 ) ), \eZ\Publish\API\Repository\Values\Content\Relation::EMBED => array( "contentIds" => array( 12 ), "locationIds" => array( 24, 45 ) ), \eZ\Publish\API\Repository\Values\Content\Relation::FIELD => array( 12 ) )