Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

eZContentClass and its attributes

Read content classes and their attributes from PHP - fetchByIdentifier(), classIDByIdentifier(), dataMap(), fetchAttributeByIdentifier(), datatype and content - using identifiers, not IDs.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-8-reference/ezcontentclass.md

On this page

eZContentClass and its attributes

Part 8, reference 8. A content class (kernel/classes/ezcontentclass.php) describes a type of content: its identifier (article), its name, and its attributes, each an eZContentClassAttribute (kernel/classes/ezcontentclassattribute.php) with an identifier, a datatype and settings. Builders create classes in the administration (Content classes for builders); extensions read them.

Identifiers, not IDs

A class's numeric ID differs between installations; its identifier does not. Write identifiers into code and settings, and look up the ID when you need it:

Method (static)Returns
classIDByIdentifier( $identifier )the ID for an identifier
classIdentifierByID( $id )the identifier for an ID
fetchByIdentifier( $identifier, $asObject = true, ... )the class
fetch( $id, $asObject = true, ... )the class by ID
fetchAllClasses( $asObject = true, $includeFilter = true, $groupList = false )every class
fetchList( ... )classes by conditions

Reading a class

Method or attributeReturns
attribute( 'identifier' ), attribute( 'id' )identifier and ID
name( $languageLocale = false )the name
dataMap()the attributes, keyed by attribute identifier
fetchAttributeByIdentifier( $identifier, $asObject = true )one attribute

For each class attribute:

Method or attributeReturns
attribute( 'identifier' )e.g. title
attribute( 'data_type_string' )the datatype, e.g. ezstring
dataType()the datatype object
content()the datatype's class-level settings (what classAttributeContent() of the datatype returns)
attribute( 'is_required' ), attribute( 'is_searchable' )flags
<?php
$class = eZContentClass::fetchByIdentifier( 'folder' );
if ( $class instanceof eZContentClass )
{
    foreach ( $class->dataMap() as $identifier => $classAttribute )
    {
        echo $identifier, ': ', $classAttribute->attribute( 'data_type_string' ), "\n";
    }
}

Run read-only on a demo installation, this listed the seven attributes of the folder class.

The content of a class attribute is the right way to read a datatype's settings. Calling a datatype method such as classAttributeContent() statically is a fatal error on PHP 8; ask the class attribute instead, as se7enxweb/sevenx_themes_media did in commit f7d93c0 (PHP 8 errors that stop old code).

Creating classes

Do not create classes with raw SQL. Use packages (Packages (.ezpkg) and the package creator), the administration, or the Content extension wizard of Setup > RAD, which writes a class as an install script.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x