Interface

eZ\Publish\API\Repository\FieldType

interface FieldType

Interface that FieldTypes expose to the public API.

Methods

string getFieldTypeIdentifier()

Returns the field type identifier for this field type.

string getName(mixed $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.

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.

mixed getEmptyValue()

Returns the empty value for this field type.

bool isEmptyValue(mixed $value)

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

mixed fromHash(mixed $hash)

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

mixed toHash(mixed $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.

ValidationError[] validateValidatorConfiguration(mixed $validatorConfiguration)

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

ValidationError[] validateFieldSettings(mixed $fieldSettings)

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

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

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

Details

at line 26
public string getFieldTypeIdentifier()

Returns the field type identifier for this field type.

Return Value

string

at line 36
public string getName(mixed $value)

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

Parameters

mixed $value

Return Value

string

at line 57
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 98
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 105
public bool isSearchable()

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

Return Value

bool

at line 112
public bool isSingular()

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

Return Value

bool

at line 119
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 126
public mixed getEmptyValue()

Returns the empty value for this field type.

Return Value

mixed

at line 141
public bool isEmptyValue(mixed $value)

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

Usually, only the value returned by {@link getEmptyValue()} is considered empty but that is not always the case.

Note: This function assumes that $value is valid so this function can only be used reliably on $values that came from the API, not from the user.

Parameters

mixed $value

Return Value

bool

at line 152
public mixed fromHash(mixed $hash)

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

This is the reverse operation to {@link toHash()}.

Parameters

mixed $hash

Return Value

mixed

at line 161
public mixed toHash(mixed $value)

Converts the given $value into a plain hash format.

Parameters

mixed $value

Return Value

mixed

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

Converts the given $fieldSettings to a simple hash format.

Parameters

mixed $fieldSettings

Return Value

array|hash|scalar|null

at line 181
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()}.

Parameters

array|hash|scalar|null $fieldSettingsHash

Return Value

mixed

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

Converts the given $validatorConfiguration to a simple hash format.

Parameters

mixed $validatorConfiguration

Return Value

array|hash|scalar|null

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

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

Parameters

array|hash|scalar|null $validatorConfigurationHash

Return Value

mixed

at line 212
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 as defined in FieldType.

Parameters

mixed $validatorConfiguration

Return Value

ValidationError[]

at line 224
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 as defined in FieldType.

Parameters

mixed $fieldSettings

Return Value

ValidationError[]

at line 234
public ValidationError[] validateValue(FieldDefinition $fieldDef, Value $value)

Validates a field value 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[]