Copied!

FieldType

FieldType.php : 29

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

Hashes:

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

Methods

publicacceptValue()

FieldType.php : 244

Potentially builds and checks the type and structure of the $inputValue.

public abstract acceptValue(mixed $inputValue) : Value

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 FieldType::getEmptyValue().

Parameters

Name Type Default value Description
$inputValue mixed - -

Return values

Value

The potentially converted and structurally plausible value.

Tags
Throws
InvalidArgumentException

if the parameter is not of the supported value sub type

Throws
InvalidArgumentException

if the value does not match the expected structure

publicapplyDefaultSettings()

FieldType.php : 175

Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.

public abstract applyDefaultSettings(mixed &$fieldSettings) : mixed

Parameters

Name Type Default value Description
$fieldSettings mixed - -
Tags
Throws
InvalidArgumentException

publicapplyDefaultValidatorConfiguration()

FieldType.php : 154

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

public abstract applyDefaultValidatorConfiguration(mixed &$validatorConfiguration) : mixed

Parameters

Name Type Default value Description
$validatorConfiguration mixed - -
Tags
Throws
InvalidArgumentException

publicfieldSettingsFromHash()

FieldType.php : 295

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

public abstract fieldSettingsFromHash(array<string|int, mixed>|scalar|null $fieldSettingsHash) : mixed

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

Parameters

Name Type Default value Description
$fieldSettingsHash array<string|int, mixed>|scalar|null - -

publicfieldSettingsToHash()

FieldType.php : 283

Converts the given $fieldSettings to a simple hash format.

public abstract fieldSettingsToHash(mixed $fieldSettings) : array<string|int, mixed>|scalar|null

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

Parameters

Name Type Default value Description
$fieldSettings mixed - -

Return values

array<string|int, mixed>|scalar|null

publicfromHash()

FieldType.php : 258

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

public abstract fromHash(mixed $hash) : Value

This is the reverse operation to FieldType::toHash(). At least the hash format generated by FieldType::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

Name Type Default value Description
$hash mixed - -

Return values

Value

publicfromPersistenceValue()

FieldType.php : 353

Converts a persistence $value to a Value.

public abstract fromPersistenceValue(FieldValue $fieldValue) : Value

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

Parameters

Name Type Default value Description
$fieldValue FieldValue - -

Return values

Value

publicgetEmptyValue()

FieldType.php : 208

Returns the empty value for this field type.

public abstract getEmptyValue() : Value

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.

Return values

Value

publicgetFieldTypeIdentifier()

FieldType.php : 42

Returns the field type identifier for this field type.

public abstract getFieldTypeIdentifier() : string

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.

Return values

string

publicgetName()

FieldType.php : 58

Returns a human readable string representation from a given value.

public abstract getName(Value $value, FieldDefinition $fieldDefinition, string $languageCode) : string

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 FieldType::acceptValue().

Parameters

Name Type Default value Description
$value Value - -
$fieldDefinition FieldDefinition - -
$languageCode string - -

Return values

string

publicgetRelations()

FieldType.php : 380

Returns relation data extracted from value.

public abstract getRelations(Value $value) : array<string|int, mixed>

Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, there is an API for handling those.

Parameters

Name Type Default value Description
$value Value - -

Return values

array<string|int, mixed>

Hash with relation type as key and array of destination content ids as value.

Example: array( \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => array( "contentIds" => array( 12, 13, 14 ), "locationIds" => array( 24 ) ), \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => array( "contentIds" => array( 12 ), "locationIds" => array( 24, 45 ) ), \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => array( 12 ) )

publicgetSettingsSchema()

FieldType.php : 79

Returns a schema for the settings expected by the FieldType.

public abstract getSettingsSchema() : mixed

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.

publicgetValidatorConfigurationSchema()

FieldType.php : 120

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

public abstract getValidatorConfigurationSchema() : mixed

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

publicisEmptyValue()

FieldType.php : 221

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

public abstract isEmptyValue(Value $value) : bool

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

Parameters

Name Type Default value Description
$value Value - -

Return values

bool

publicisSearchable()

FieldType.php : 182

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

public abstract isSearchable() : bool

Return values

bool

publicisSingular()

FieldType.php : 189

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

public abstract isSingular() : bool

Return values

bool

publiconlyEmptyInstance()

FieldType.php : 196

Indicates if the field definition of this type can be added to a ContentType with Content instances.

public abstract onlyEmptyInstance() : bool

Return values

bool

publictoHash()

FieldType.php : 272

Converts the given $value into a plain hash format.

public abstract toHash(Value $value) : mixed

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

Name Type Default value Description
$value Value - -

publictoPersistenceValue()

FieldType.php : 342

Converts a $value to a persistence value.

public abstract toPersistenceValue(Value $value) : FieldValue

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

Parameters

Name Type Default value Description
$value Value -

The value of the field type

Return values

FieldValue

the value processed by the storage engine

Tags
See
FieldValue

publicvalidate()

FieldType.php : 132

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

public abstract validate(FieldDefinition $fieldDef, Value $value) : array<string|int, ValidationError>

Parameters

Name Type Default value Description
$fieldDef FieldDefinition -

The field definition of the field

$value Value -

The field value for which an action is performed

Return values

array<string|int, ValidationError>

Tags
Throws
InvalidArgumentException

publicvalidateFieldSettings()

FieldType.php : 166

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

public abstract validateFieldSettings(mixed $fieldSettings) : array<string|int, ValidationError>

This methods determines if the given $fieldSettings are structurally correct and comply to the settings schema returned by FieldType::getSettingsSchema().

Parameters

Name Type Default value Description
$fieldSettings mixed - -

Return values

array<string|int, ValidationError>

publicvalidateValidatorConfiguration()

FieldType.php : 145

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

public abstract validateValidatorConfiguration(mixed $validatorConfiguration) : array<string|int, ValidationError>

This methods determines if the given $validatorConfiguration is structurally correct and complies to the validator configuration schema returned by FieldType::getValidatorConfigurationSchema().

Parameters

Name Type Default value Description
$validatorConfiguration mixed - -

Return values

array<string|int, ValidationError>

publicvalidatorConfigurationFromHash()

FieldType.php : 318

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

public abstract validatorConfigurationFromHash(array<string|int, mixed>|scalar|null $validatorConfigurationHash) : mixed

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

Parameters

Name Type Default value Description
$validatorConfigurationHash array<string|int, mixed>|scalar|null - -

publicvalidatorConfigurationToHash()

FieldType.php : 306

Converts the given $validatorConfiguration to a simple hash format.

public abstract validatorConfigurationToHash(mixed $validatorConfiguration) : array<string|int, mixed>|scalar|null

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

Parameters

Name Type Default value Description
$validatorConfiguration mixed - -

Return values

array<string|int, mixed>|scalar|null