Copied!

Type

Type.php : 24
Extends FieldType

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.

Properties

protected $serializer

Type.php : 27
protected ValueSerializerInterface $serializer

protected $validator

Type.php : 30
protected ValidatorInterface $validator

Methods

public__construct()

Type.php : 32
public __construct(ValueSerializerInterface $serializer, ValidatorInterface $validator)

Parameters

Name Type Default value Description
$serializer ValueSerializerInterface - -
$validator ValidatorInterface - -

publicacceptValue()

Type.php : 240

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

public final 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.

publicapplyDefaultSettings()

Type.php : 169

Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct.

public applyDefaultSettings(mixed &$fieldSettings) : void

Parameters

Name Type Default value Description
$fieldSettings mixed - -

publicapplyDefaultValidatorConfiguration()

Type.php : 131

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

public applyDefaultValidatorConfiguration(mixed &$validatorConfiguration) : void

Parameters

Name Type Default value Description
$validatorConfiguration mixed - -

publicfieldSettingsFromHash()

Type.php : 340

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

public fieldSettingsFromHash(mixed $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 mixed - -

publicfieldSettingsToHash()

Type.php : 335

Converts the given $fieldSettings to a simple hash format.

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

Type.php : 50

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

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

Type.php : 215

Converts a persistence $value to a Value.

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

Type.php : 43

Returns the empty value for this field type.

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

Type.php : 38

Returns a human readable string representation from a given value.

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

Type.php : 355

Returns relation data extracted from value.

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

Type.php : 96

Returns a schema for the settings expected by the FieldType.

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

Type.php : 101

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

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

Type.php : 235

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

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

Type.php : 220

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

public isSearchable() : bool

Return values

bool

publicisSingular()

Type.php : 225

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

public isSingular() : bool

Return values

bool

publiconlyEmptyInstance()

Type.php : 230

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

public onlyEmptyInstance() : bool

Return values

bool

publictoHash()

Type.php : 59

Converts the given $value into a plain hash format.

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

Type.php : 204

Converts a $value to a persistence value.

public 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

publicvalidate()

Type.php : 106

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

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

Parameters

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

The field value for which an action is performed

Return values

array<string|int, ValidationError>

publicvalidateFieldSettings()

Type.php : 152

Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

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

Type.php : 117

Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.

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

Type.php : 350

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

public validatorConfigurationFromHash(mixed $validatorConfiguration) : mixed

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

Parameters

Name Type Default value Description
$validatorConfiguration mixed - -

publicvalidatorConfigurationToHash()

Type.php : 345

Converts the given $validatorConfiguration to a simple hash format.

public 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

protectedcheckValueType()

Type.php : 327

Throws an exception if the given $value is not an instance of the supported value subtype.

protected checkValueType(mixed $value) : void

This is an operation method for acceptValue().

Default implementation expects the value class to reside in the same namespace as its FieldType class and is named "Value".

Example implementation: protected function checkValueType($value): void { if ( !$inputValue instanceof \My\FieldType\CookieJar\Value ) ) { throw new InvalidArgumentException( "Given value type is not supported." ); } }

Parameters

Name Type Default value Description
$value mixed -

A value returned by createValueFromInput().

Tags
Throws
InvalidArgumentException

If the parameter is not an instance of the supported value subtype.

protectedcreateValueFromInput()

Type.php : 282

Inspects given $inputValue and potentially converts it into a dedicated value object.

protected createValueFromInput(mixed $inputValue) : mixed

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

Example implementation: protected function createValueFromInput( $inputValue ) { if ( is_array( $inputValue ) ) { $inputValue = \My\FieldType\CookieJar\Value( $inputValue ); }

 return $inputValue;

}

Parameters

Name Type Default value Description
$inputValue mixed - -

Return values

mixed

The potentially converted input value.

protectedgetFieldSettingsConstraints()

Type.php : 71
protected getFieldSettingsConstraints() : Collection|null

Return values

Collection|null

Tags
See
https://symfony.com/doc/current/validation/raw_values.html

protectedgetFieldValueConstraints()

Type.php : 79
protected getFieldValueConstraints(FieldDefinition $fieldDefinition) : Collection|null

Parameters

Name Type Default value Description
$fieldDefinition FieldDefinition - -

Return values

Collection|null

Tags
See
https://symfony.com/doc/current/validation/raw_values.html

protectedgetSortInfo()

Type.php : 199

Returns information for FieldValue->$sortKey relevant to the field type.

protected getSortInfo(Value $value) : mixed

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.

In case of multi value, values should be string and separated by "-" or ",".

Parameters

Name Type Default value Description
$value Value - -

protectedgetValueClass()

Type.php : 299

Returns FQN of class representing Field Type Value.

protected getValueClass() : string

Return values

string

protectedmapConstraintViolationList()

Type.php : 84
protected mapConstraintViolationList(ConstraintViolationListInterface $constraintViolationList) : array<string|int, mixed>

Parameters

Name Type Default value Description
$constraintViolationList ConstraintViolationListInterface - -

Return values

array<string|int, mixed>