Adding properties to an entity type

Last updated on
30 April 2025

We can easily add new properties to an entity type by using the addProperty method.

$entity_type->addProperty('name', 'Name',  'text');

If you look at the method definition in eck.classes.inc, you will notice that the method has 4 arguments; 3 are required and 1 is optional.

The required arguments are 'name', 'label', and 'type'.

Like in many other places in Drupal, the 'name' serves to identify the property we are creating, and the 'label' is used for display in a UI, for example.

The 'type' argument defines the type of data that can be stored in that property. Currently, the supported types are 'text', 'integer', 'decimal', 'positive_integer', and 'uuid'.

If you want more information on what the schema looks like, refer to the function eck_property_type_schema() in eck.properties.inc.

The last, optional, argument in this method is a behavior. Property behaviors make properties useful; for example, a 'uid' property might keep track of who created an entity. There will be more about behaviors later on in the documentation.

Help improve this page

Page status: Not set

You can: