eZPublishCommunityProject  2013.4
eZ\Publish\SPI\FieldType\FieldType Interface Reference

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

Public Member Functions

 acceptValue ($inputValue)
 Potentially builds and checks the type and structure of the $inputValue. More...
 
 fieldSettingsFromHash ($fieldSettingsHash)
 Converts the given $fieldSettingsHash to field settings of the type. More...
 
 fieldSettingsToHash ($fieldSettings)
 Converts the given $fieldSettings to a simple hash format. More...
 
 fromHash ($hash)
 Converts an $hash to the Value defined by the field type. More...
 
 fromPersistenceValue (FieldValue $fieldValue)
 Converts a persistence $fieldValue to a Value. More...
 
 getEmptyValue ()
 Returns the empty value for this field type. More...
 
 getFieldTypeIdentifier ()
 Returns the field type identifier for this field type. More...
 
 getName ($value)
 Returns a human readable string representation from the given $value. More...
 
 getRelations ($fieldValue)
 Returns relation data extracted from value. More...
 
 getSettingsSchema ()
 Returns a schema for the settings expected by the FieldType. More...
 
 getValidatorConfigurationSchema ()
 Returns a schema for the validator configuration expected by the FieldType. More...
 
 isEmptyValue ($value)
 Returns if the given $value is considered empty by the field type. More...
 
 isSearchable ()
 Indicates if the field type supports indexing and sort keys for searching. More...
 
 toHash ($value)
 Converts the given $value into a plain hash format. More...
 
 toPersistenceValue ($value)
 Converts a $value to a persistence value. More...
 
 validate (FieldDefinition $fieldDef, $fieldValue)
 Validates a field based on the validator configuration in the field definition. More...
 
 validateFieldSettings ($fieldSettings)
 Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. More...
 
 validateValidatorConfiguration ($validatorConfiguration)
 Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. More...
 
 validatorConfigurationFromHash ($validatorConfigurationHash)
 Converts the given $validatorConfigurationHash to a validator configuration of the type. More...
 
 validatorConfigurationToHash ($validatorConfiguration)
 Converts the given $validatorConfiguration to a simple hash format. More...
 

Detailed Description

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

Hashes:

The 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 fromHash() method must convert such a representation back into a value, which is understood by the FieldType.

Member Function Documentation

eZ\Publish\SPI\FieldType\FieldType::acceptValue (   $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 getEmptyValue().

Exceptions
\eZ\Publish\API\Repository\Exceptions\InvalidArgumentExceptionif the parameter is not of the supported value sub type
\eZ\Publish\API\Repository\Exceptions\InvalidArgumentExceptionif the value does not match the expected structure
Parameters
mixed$inputValue
Returns
The potentially converted and structurally plausible value.
eZ\Publish\SPI\FieldType\FieldType::fieldSettingsFromHash (   $fieldSettingsHash)

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

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

Parameters
array | hash | scalar | null$fieldSettingsHash
Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::fieldSettingsToHash (   $fieldSettings)

Converts the given $fieldSettings to a simple hash format.

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

Parameters
mixed$fieldSettings
Returns
array|hash|scalar|null
eZ\Publish\SPI\FieldType\FieldType::fromHash (   $hash)

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

This is the reverse operation to toHash(). At least the hash format generated by 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
Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::fromPersistenceValue ( FieldValue  $fieldValue)

Converts a persistence $fieldValue to a Value.

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

Parameters
\eZ\Publish\SPI\Persistence\Content\FieldValue$fieldValue
Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::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.

Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::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.

Returns
string
eZ\Publish\SPI\FieldType\FieldType::getName (   $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 acceptValue().

Parameters
mixed$value
Returns
string
eZ\Publish\SPI\FieldType\FieldType::getRelations (   $fieldValue)

Returns relation data extracted from value.

Not intended for ::COMMON type relations, there is an API for handling those.

Parameters
mixed$fieldValue
Returns
array Hash with relation type as key and array of destination content ids as value.

Example: array( ::LINK => array( "contentIds" => array( 12, 13, 14 ), "locationIds" => array( 24 ) ), ::EMBED => array( "contentIds" => array( 12 ), "locationIds" => array( 24, 45 ) ), ::ATTRIBUTE => array( 12 ) )

eZ\Publish\SPI\FieldType\FieldType::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.

Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::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, ) ), );

Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::isEmptyValue (   $value)

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

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

Parameters
mixed$value
Returns
boolean
eZ\Publish\SPI\FieldType\FieldType::isSearchable ( )

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

Returns
boolean
eZ\Publish\SPI\FieldType\FieldType::toHash (   $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
mixed$value
Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::toPersistenceValue (   $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) 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.

See Also
Parameters
mixed$valueThe value of the field type
Returns
the value processed by the storage engine
eZ\Publish\SPI\FieldType\FieldType::validate ( FieldDefinition  $fieldDef,
  $fieldValue 
)

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

Exceptions
\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
Parameters
\eZ\Publish\API\Repository\Values\ContentType\FieldDefinition$fieldDefThe field definition of the field
\eZ\Publish\Core\FieldType\Value$fieldValueThe field value for which an action is performed
Returns
[]
eZ\Publish\SPI\FieldType\FieldType::validateFieldSettings (   $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 getSettingsSchema().

Parameters
mixed$fieldSettings
Returns
[]
eZ\Publish\SPI\FieldType\FieldType::validateValidatorConfiguration (   $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 getValidatorConfigurationSchema().

Parameters
mixed$validatorConfiguration
Returns
[]
eZ\Publish\SPI\FieldType\FieldType::validatorConfigurationFromHash (   $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
Returns
mixed
eZ\Publish\SPI\FieldType\FieldType::validatorConfigurationToHash (   $validatorConfiguration)

Converts the given $validatorConfiguration to a simple hash format.

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

Parameters
mixed$validatorConfiguration
Returns
array|hash|scalar|null

The documentation for this interface was generated from the following file: