PHP Class eZ\Publish\Core\FieldType\FieldType

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.
Inheritance: implements eZ\Publish\SPI\FieldType\FieldType
Datei anzeigen Open project: ezsystems/ezpublish-kernel Class Usage Examples

Protected Properties

Property Type Description
$settingsSchema mixed The key is the setting name, and the value is the default value for given setting, set to null if no particular default should be set.
$transformationProcessor eZ\Publish\Core\Persistence\TransformationProcessor String transformation processor, used to normalize sort string as needed.
$validatorConfigurationSchema mixed This is a base implementation, containing an empty array() that indicates that no validators are supported. Overwrite in derived types, if validation is supported.

Public Methods

Method Description
acceptValue ( mixed $inputValue ) : Value Potentially builds and checks the type and structure of the $inputValue.
applyDefaultSettings ( mixed &$fieldSettings ) Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.
applyDefaultValidatorConfiguration ( mixed &$validatorConfiguration ) Applies the default values to the given $validatorConfiguration of a FieldDefinitionCreateStruct.
fieldSettingsFromHash ( array | hash | scalar | null $fieldSettingsHash ) : mixed Converts the given $fieldSettingsHash to field settings of the type.
fieldSettingsToHash ( mixed $fieldSettings ) : array | hash | scalar | null Converts the given $fieldSettings to a simple hash format.
fromPersistenceValue ( eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue ) : Value Converts a persistence $fieldValue to a Value.
getRelations ( eZ\Publish\SPI\FieldType\Value $fieldValue ) : array Returns relation data extracted from value.
getSettingsSchema ( ) : mixed Returns a schema for the settings expected by the FieldType.
getValidatorConfigurationSchema ( ) : mixed Returns a schema for the validator configuration expected by the FieldType.
isEmptyValue ( eZ\Publish\SPI\FieldType\Value $value ) : boolean Returns if the given $value is considered empty by the field type.
isSearchable ( ) : boolean Returns whether the field type is searchable.
isSingular ( ) : boolean Indicates if the field definition of this type can appear only once in the same ContentType.
onlyEmptyInstance ( ) : boolean Indicates if the field definition of this type can be added to a ContentType with Content instances.
setTransformationProcessor ( TransformationProcessor $transformationProcessor )
toPersistenceValue ( eZ\Publish\SPI\FieldType\Value $value ) : eZ\Publish\SPI\Persistence\Content\FieldValue Converts a $value to a persistence value.
validate ( eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition, eZ\Publish\SPI\FieldType\Value $value ) : eZ\Publish\SPI\FieldType\ValidationError[] Validates a field based on the validators in the field definition.
validateFieldSettings ( mixed $fieldSettings ) : eZ\Publish\SPI\FieldType\ValidationError[] Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
validateValidatorConfiguration ( mixed $validatorConfiguration ) : eZ\Publish\SPI\FieldType\ValidationError[] Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
validatorConfigurationFromHash ( array | hash | scalar | null $validatorConfigurationHash ) : mixed Converts the given $validatorConfigurationHash to a validator configuration of the type.
validatorConfigurationToHash ( mixed $validatorConfiguration ) : array | hash | scalar | null Converts the given $validatorConfiguration to a simple hash format.

Protected Methods

Method Description
checkValueStructure ( Value $value ) Throws an exception if value structure is not of expected format.
checkValueType ( mixed $value ) Throws an exception if the given $value is not an instance of the supported value subtype.
createValueFromInput ( mixed $inputValue ) : mixed Inspects given $inputValue and potentially converts it into a dedicated value object.
getSortInfo ( Value $value ) : mixed Returns information for FieldValue->$sortKey relevant to the field type.

Method Details

acceptValue() final public method

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()}.
final public acceptValue ( mixed $inputValue ) : Value
$inputValue mixed
return Value The potentially converted and structurally plausible value.

applyDefaultSettings() public method

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.
public applyDefaultSettings ( mixed &$fieldSettings )
$fieldSettings mixed

applyDefaultValidatorConfiguration() public method

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.
public applyDefaultValidatorConfiguration ( mixed &$validatorConfiguration )
$validatorConfiguration mixed

checkValueStructure() abstract protected method

Note that this does not include validation after the rules from validators, but only plausibility checks for the general data format. This is an operation method for {@see \acceptValue()}. Example implementation: protected function checkValueStructure( Value $value ) { if ( !is_array( $value->cookies ) ) { throw new InvalidArgumentException( "An array of assorted cookies was expected." ); } }
abstract protected checkValueStructure ( Value $value )
$value Value

checkValueType() protected static method

This is an operation method for {@see \acceptValue()}. Default implementation expects the value class to reside in the same namespace as its FieldType class and is named "Value". Example implementation: static protected function checkValueType( $value ) { if ( !$inputValue instanceof \eZ\Publish\Core\FieldType\CookieJar\Value ) ) { throw new InvalidArgumentException( "Given value type is not supported." ); } }
protected static checkValueType ( mixed $value )
$value mixed A value returned by {@see \createValueFromInput()}.

createValueFromInput() abstract protected method

If given $inputValue could not be converted or is already an instance of dedicate value object, the method should simply return it. This is an operation method for {@see \acceptValue()}. Example implementation: protected function createValueFromInput( $inputValue ) { if ( is_array( $inputValue ) ) { $inputValue = \eZ\Publish\Core\FieldType\CookieJar\Value( $inputValue ); } return $inputValue; }
abstract protected createValueFromInput ( mixed $inputValue ) : mixed
$inputValue mixed
return mixed The potentially converted input value.

fieldSettingsFromHash() public method

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.
public fieldSettingsFromHash ( array | hash | scalar | null $fieldSettingsHash ) : mixed
$fieldSettingsHash array | hash | scalar | null
return mixed

fieldSettingsToHash() public method

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.
public fieldSettingsToHash ( mixed $fieldSettings ) : array | hash | scalar | null
$fieldSettings mixed
return array | hash | scalar | null

fromPersistenceValue() public method

Converts a persistence $fieldValue to a Value.
public fromPersistenceValue ( eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue ) : Value
$fieldValue eZ\Publish\SPI\Persistence\Content\FieldValue
return Value

getRelations() public method

Not intended for \eZ\Publish\API\Repository\Values\Content\Relation::COMMON type relations, there is an API for handling those.
public getRelations ( eZ\Publish\SPI\FieldType\Value $fieldValue ) : array
$fieldValue eZ\Publish\SPI\FieldType\Value
return 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 ) )

getSettingsSchema() public method

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.
public getSettingsSchema ( ) : mixed
return mixed

getSortInfo() protected method

Return value is mixed. It should be something which is sensible for sorting. It is up to the persistence implementation to handle those values. Common string and integer values are safe. For the legacy storage it is up to the field converters to set this value in either sort_key_string or sort_key_int.
protected getSortInfo ( Value $value ) : mixed
$value Value
return mixed

getValidatorConfigurationSchema() public method

Returns a schema for the validator configuration expected by the FieldType.
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). array( 'stringLength' => array( 'minStringLength' => array( 'type' => 'int', 'default' => 0, ), 'maxStringLength' => array( 'type' => 'int' 'default' => null, ) ), );

isEmptyValue() public method

Default implementation, which performs a "==" check with the value returned by {@link getEmptyValue()}. Overwrite in the specific field type, if necessary.
public isEmptyValue ( eZ\Publish\SPI\FieldType\Value $value ) : boolean
$value eZ\Publish\SPI\FieldType\Value
return boolean

isSearchable() public method

Returns whether the field type is searchable.
public isSearchable ( ) : boolean
return boolean

isSingular() public method

Indicates if the field definition of this type can appear only once in the same ContentType.
public isSingular ( ) : boolean
return boolean

onlyEmptyInstance() public method

Indicates if the field definition of this type can be added to a ContentType with Content instances.
public onlyEmptyInstance ( ) : boolean
return boolean

setTransformationProcessor() public method

public setTransformationProcessor ( TransformationProcessor $transformationProcessor )
$transformationProcessor eZ\Publish\Core\Persistence\TransformationProcessor

toPersistenceValue() public method

Converts a $value to a persistence value.
public toPersistenceValue ( eZ\Publish\SPI\FieldType\Value $value ) : eZ\Publish\SPI\Persistence\Content\FieldValue
$value eZ\Publish\SPI\FieldType\Value
return eZ\Publish\SPI\Persistence\Content\FieldValue

validate() public method

This is a base implementation, returning an empty array() that indicates that no validation errors occurred. Overwrite in derived types, if validation is supported.
public validate ( eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition, eZ\Publish\SPI\FieldType\Value $value ) : eZ\Publish\SPI\FieldType\ValidationError[]
$fieldDefinition eZ\Publish\API\Repository\Values\ContentType\FieldDefinition The field definition of the field
$value eZ\Publish\SPI\FieldType\Value The field value for which an action is performed
return eZ\Publish\SPI\FieldType\ValidationError[]

validateFieldSettings() public method

This method expects that given $fieldSettings are complete, for this purpose method {@link self::applyDefaultSettings()} is provided.
public validateFieldSettings ( mixed $fieldSettings ) : eZ\Publish\SPI\FieldType\ValidationError[]
$fieldSettings mixed
return eZ\Publish\SPI\FieldType\ValidationError[]

validateValidatorConfiguration() public method

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.
public validateValidatorConfiguration ( mixed $validatorConfiguration ) : eZ\Publish\SPI\FieldType\ValidationError[]
$validatorConfiguration mixed
return eZ\Publish\SPI\FieldType\ValidationError[]

validatorConfigurationFromHash() public method

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.
public validatorConfigurationFromHash ( array | hash | scalar | null $validatorConfigurationHash ) : mixed
$validatorConfigurationHash array | hash | scalar | null
return mixed

validatorConfigurationToHash() public method

Default implementation, which just returns the given $validatorConfiguration, which is by convention an array for all internal field types. Overwrite this method, if necessary.
public validatorConfigurationToHash ( mixed $validatorConfiguration ) : array | hash | scalar | null
$validatorConfiguration mixed
return array | hash | scalar | null

Property Details

$settingsSchema protected_oe property

The key is the setting name, and the value is the default value for given setting, set to null if no particular default should be set.
protected mixed $settingsSchema
return mixed

$transformationProcessor protected_oe property

String transformation processor, used to normalize sort string as needed.
protected TransformationProcessor,eZ\Publish\Core\Persistence $transformationProcessor
return eZ\Publish\Core\Persistence\TransformationProcessor

$validatorConfigurationSchema protected_oe property

This is a base implementation, containing an empty array() that indicates that no validators are supported. Overwrite in derived types, if validation is supported.
See also: getValidatorConfigurationSchema()
protected mixed $validatorConfigurationSchema
return mixed