Class

eZ\Publish\Core\Repository\Values\ContentType\FieldType

class FieldType implements FieldType

This class represents a FieldType available to Public API users.

Methods

__construct(FieldType $fieldType)

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 fallback default value of field type when no such default value is provided in the field definition in content types.

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 a Value to a hash.

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 35
public __construct(FieldType $fieldType)

Parameters

FieldType $fieldType

at line 45
public string getFieldTypeIdentifier()

Returns the field type identifier for this field type.

Return Value

string

at line 50
public string getName(mixed $value)

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

Parameters

mixed $value

Return Value

string

at line 74
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 118
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 128
public bool isSearchable()

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

Return Value

bool

at line 138
public bool isSingular()

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

Return Value

bool

at line 148
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 159
public mixed getEmptyValue()

Returns the fallback default value of field type when no such default value is provided in the field definition in content types.

Return Value

mixed

at line 177
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 189
public mixed fromHash(mixed $hash)

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

Parameters

mixed $hash

Return Value

mixed

at line 201
public mixed toHash(mixed $value)

Converts a Value to a hash.

Parameters

mixed $value

Return Value

mixed

at line 213
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 227
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 239
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 252
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 267
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 282
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 295
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[]