Class

eZ\Publish\Core\FieldType\FieldType

abstract class FieldType implements FieldType

Base class for field types, the most basic storage unit of data inside eZ Publish.

All other field types extend FieldType providing the specific functionality desired in each case.

The capabilities supported by each individual field type is decided by which interfaces the field type implements support for. These individual capabilities can also be checked via the supports*() methods.

Field types are the base building blocks of Content Types, and serve as data containers for Content objects. Therefore, while field types can be used independently, they are designed to be used as a part of a Content object.

Field types are primed and pre-configured with the Field Definitions found in Content Types.

Methods

setTransformationProcessor(TransformationProcessor $transformationProcessor)

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 $fieldDefinition, Value $value)

Validates a field based on the validators 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.

FieldValue toPersistenceValue(Value $value)

Converts a $value to a persistence value.

Value fromPersistenceValue(FieldValue $fieldValue)

Converts a persistence $fieldValue to a Value.

bool isSearchable()

Returns whether the field type is searchable.

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.

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.

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.

array getRelations(Value $fieldValue)

Returns relation data extracted from value.

Details

at line 70
public setTransformationProcessor(TransformationProcessor $transformationProcessor)

Parameters

TransformationProcessor $transformationProcessor

at line 84
public mixed getSettingsSchema()

Returns a schema for the settings expected by the FieldType.

This implementation returns an array. where the key is the setting name, and the value is the default value for given setting and set to null if no particular default should be set.

Return Value

mixed

at line 115
public mixed getValidatorConfigurationSchema()

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

Return Value

mixed

See also

FieldTypeInterface::getValidatorConfigurationSchema() This implementation returns a three dimensional map containing for each validator configuration referenced by identifier a map of supported parameters which are defined by a type and a default value (see example). <code> array( 'stringLength' => array( 'minStringLength' => array( 'type' => 'int', 'default' => 0, ), 'maxStringLength' => array( 'type' => 'int' 'default' => null, ) ), ); </code>

at line 134
public ValidationError[] validate(FieldDefinition $fieldDefinition, Value $value)

Validates a field based on the validators in the field definition.

This is a base implementation, returning an empty array() that indicates that no validation errors occurred. Overwrite in derived types, if validation is supported.

Parameters

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

Return Value

ValidationError[]

Exceptions

InvalidArgumentException

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

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

This method expects that given $validatorConfiguration is complete, for this purpose method {@link self::applyDefaultValidatorConfiguration()} is provided.

This is a base implementation, returning a validation error for each specified validator, since by default no validators are supported. Overwrite in derived types, if validation is supported.

Parameters

mixed $validatorConfiguration

Return Value

ValidationError[]

at line 181
public applyDefaultValidatorConfiguration(mixed $validatorConfiguration)

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

This is a base implementation, expecting best practice validator configuration format used by field types in standard eZ publish installation. Overwrite in derived types if needed.

Parameters

mixed $validatorConfiguration

Exceptions

InvalidArgumentException

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

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

This method expects that given $fieldSettings are complete, for this purpose method {@link self::applyDefaultSettings()} is provided.

Parameters

mixed $fieldSettings

Return Value

ValidationError[]

at line 240
public applyDefaultSettings(mixed $fieldSettings)

Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.

This is a base implementation, expecting best practice field settings format used by field types in standard eZ publish installation. Overwrite in derived types if needed.

Parameters

mixed $fieldSettings

Exceptions

InvalidArgumentException

at line 282
public FieldValue toPersistenceValue(Value $value)

Converts a $value to a persistence value.

Parameters

Value $value The value of the field type

Return Value

FieldValue the value processed by the storage engine

at line 303
public Value fromPersistenceValue(FieldValue $fieldValue)

Converts a persistence $fieldValue to a Value.

Parameters

FieldValue $fieldValue

Return Value

Value

at line 313
public bool isSearchable()

Returns whether the field type is searchable.

Return Value

bool

at line 323
public bool isSingular()

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

Return Value

bool

at line 333
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 349
public bool isEmptyValue(Value $value)

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

Default implementation, which performs a "==" check with the value returned by {@link getEmptyValue()}. Overwrite in the specific field type, if necessary.

Parameters

Value $value

Return Value

bool

at line 375
final 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 491
public array|hash|scalar|null fieldSettingsToHash(mixed $fieldSettings)

Converts the given $fieldSettings to a simple hash format.

This is the default implementation, which just returns the given $fieldSettings, assuming they are already in a hash format. Overwrite this in your specific implementation, if necessary.

Parameters

mixed $fieldSettings

Return Value

array|hash|scalar|null

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

This is the default implementation, which just returns the given $fieldSettingsHash, assuming the supported field settings are already in a hash format. Overwrite this in your specific implementation, if necessary.

Parameters

array|hash|scalar|null $fieldSettingsHash

Return Value

mixed

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

Converts the given $validatorConfiguration to a simple hash format.

Default implementation, which just returns the given $validatorConfiguration, which is by convention an array for all internal field types. Overwrite this method, if necessary.

Parameters

mixed $validatorConfiguration

Return Value

array|hash|scalar|null

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

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

Default implementation, which just returns the given $validatorConfigurationHash, since the validator configuration is by convention an array for all internal field types. Overwrite this method, if necessary.

Parameters

array|hash|scalar|null $validatorConfigurationHash

Return Value

mixed

at line 574
public array getRelations(Value $fieldValue)

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 $fieldValue

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 ) )