Datatypes
A datatype is the kind of value a class attribute holds. It decides how the value is entered in the edit form, checked, stored, indexed for search, compared, exported and shown in templates. When you add an attribute to a class you choose its datatype, and it cannot be changed afterwards.
The datatypes of the kernel
The datatypes that can be chosen for new attributes are listed in content.ini [DataTypeSettings] AvailableDataTypes[]. Exponential 6.0.15 ships 35:
| Group | Datatypes (identifier) |
|---|---|
| Text | Text line (ezstring), Text block (eztext), Rich text (ezxmltext), Email (ezemail), URL (ezurl), ISBN (ezisbn), Identifier (ezidentifier), Keywords (ezkeyword) |
| Numbers and dates | Integer (ezinteger), Float (ezfloat), Checkbox (ezboolean), Date (ezdate), Date and time (ezdatetime), Time (eztime) |
| Choices | Selection (ezselection), Enum (ezenum), Country (ezcountry), Matrix (ezmatrix) |
| Files | Image (ezimage), File (ezbinaryfile), Media (ezmedia) |
| Relations | Object relation (ezobjectrelation), Object relations (ezobjectrelationlist), Authors (ezauthor) |
| Shop | Price (ezprice), Multi-price (ezmultiprice), Option (ezoption), Multi-option (ezmultioption, ezmultioption2), Range option (ezrangeoption), Product category (ezproductcategory) |
| Users and system | User account (ezuser), Subtree subscription (ezsubtreesubscription), Ini setting (ezinisetting), Package (ezpackage) |
Extensions add more, for example tags (eztags) or a map location (ezgmaplocation). Setup > Datatypes in the administration (/class/datatype/list) lists every registered datatype, who provides it and how much content uses it, and points out content whose datatype is no longer registered. See the Datatypes guide; each kernel datatype is described in All datatypes.
How a datatype stores its value
Every object attribute row has a few generic columns: data_text, data_int, data_float and sort_key_string or sort_key_int. A datatype chooses which it uses: a text line keeps its text in data_text, a checkbox its value in data_int. Some datatypes keep more in tables of their own (an image's files and aliases, a URL in the shared URL table, keywords in their own tables) or in files below var/. The class attribute has similar columns (data_int1 to data_int4, data_text1 to data_text5 and others) for the datatype's settings, such as a default value or a maximum size.
In templates
Each datatype has a view template and an edit template, content/datatype/view/<identifier>.tpl and content/datatype/edit/<identifier>.tpl, found through the design's search order and override rules. attribute_view_gui and attribute_edit_gui call them; .content gives the datatype's value as a PHP value or object:
{attribute_view_gui attribute=$node.data_map.body}
{$node.data_map.price.content.price|l10n( 'currency' )}
{$node.data_map.image.content['medium'].url|ezroot}
Your own datatype
A datatype is a PHP class that extends eZDataType, registered with eZDataType::register(). An extension makes it available by naming its directory and the identifier in content.ini:
<?php /* #?ini charset="utf-8"? [DataTypeSettings] ExtensionDirectories[]=myextension AvailableDataTypes[]=mydatatype */ ?>
The file goes into extension/myextension/datatypes/mydatatype/mydatatypetype.php, with its templates in the extension's design. Extending Exponential 6.0 describes the whole process.
Contributors
- Balazs Halasy
- Geir Arne Waaler
- Graham Brookins Updated Maintainer
Comments
Add a comment