The eZDataType API #
Part 8, reference 16. A datatype is a class that extends eZDataType (kernel/classes/ezdatatype.php) and overrides
the methods it needs. This page lists them by purpose, with the signatures of the base class (copy them exactly: PHP
8 refuses an override whose signature differs). How to build one is in Datatypes,
Datatype storage, validation and templates
and the tutorials A datatype, by hand and
With RAD: a datatype.
Registration #
| Method | Notes |
|---|
public function __construct( $dataTypeString, $name, $properties = array() ) | call it from your constructor with your datatype string and translated name |
static function register( $dataTypeString, $className ) | call once at the end of the file: eZDataType::register( 'mydatatype', 'myDataTypeType' ); |
Plus content.ini [DataTypeSettings] ExtensionDirectories[] and AvailableDataTypes[].
Editing an object's attribute #
| Method | Called when |
|---|
initializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute ) | a new version is created: copy or set defaults |
validateObjectAttributeHTTPInput( $http, $base, $objectAttribute ) | the edit form is posted; return eZInputValidator::STATE_ACCEPTED or STATE_INVALID |
fetchObjectAttributeHTTPInput( $http, $base, $objectAttribute ) | after validation: read the posted value into the attribute; return true if something was read |
customObjectAttributeHTTPAction( $http, $action, $objectAttribute, $parameters ) | a custom button of your edit template was pressed |
The posted field names follow the kernel's convention of base, datatype string, field and attribute ID:
ezstring reads $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ). Your edit template
must post exactly the names your class reads.
Storage and content #
| Method | Use |
|---|
storeObjectAttribute( $objectAttribute ) | before the attribute row is stored |
objectAttributeContent( $objectAttribute ) | what $attribute.content is in templates and attribute( 'content' ) in PHP |
hasObjectAttributeContent( $contentObjectAttribute ) | whether the attribute is filled |
onPublish( $contentObjectAttribute, $contentObject, $publishedNodes ) | when the version is published |
deleteStoredObjectAttribute( $objectAttribute, $version = null ) | before the stored data is removed (delete files you stored) |
Class settings #
| Method | Use |
|---|
validateClassAttributeHTTPInput( $http, $base, $classAttribute ) | the class edit form is posted |
fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) | read the class-level settings |
storeClassAttribute( $classAttribute, $version ) | before the class attribute is stored |
classAttributeContent( $classAttribute ) | what $class_attribute.content is |
| Method | Use |
|---|
isInformationCollector() | return true if the attribute can collect input from visitors |
validateCollectionAttributeHTTPInput( $http, $base, $objectAttribute ) | validate a visitor's input |
fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $objectAttribute ) | store it |
Search, sorting, naming #
| Method | Use |
|---|
isIndexable() | whether the search engine indexes it |
metaData( $contentObjectAttribute ) | the text to index |
sortKey( $objectAttribute ), sortKeyType() | the value and type ('int' or 'string') for sorting by this attribute |
title( $objectAttribute, $name = null ) | the text used in object names |
Import, export, packages #
| Method | Use |
|---|
toString( $objectAttribute ), fromString( $objectAttribute, $string ) | the attribute as a string, for imports, exports and some tools |
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ), unserializeContentClassAttribute( ... ) | the class settings in a package |
Templates #
A datatype draws nothing without its templates, found through the design chain:
content/datatype/view/<datatypestring>.tpl and content/datatype/edit/<datatypestring>.tpl, plus
class/datatype/view/ and class/datatype/edit/ for class settings. The extension needs
design.ini [ExtensionSettings] DesignExtensions[] so they are found.
Related pages #
Become an Exponential Partner
Partners share their information, provide funding, contribute back and
develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for
mid-2027: please become a partner today to speed up our growth rate and land new features faster.