Content Entity
Last updated on
16 June 2021
This cheat sheet provides an overview of the frequently used methods, classes, and interfaces for content entities.
Content entities inherit many of their behavior from entities. See Working with the Entity API for these generic functions.
Manipulating field values
- Create custom fields using the
baseFieldDefinitions()
method for the content entity - Define a custom field called custom_field
- Store a custom entity instance in a local variable (
$custom_entity
) - Store some data
Example code
$custom_field_value = $custom_entity->custom_field->value;
// Manipulate the field data.
// Store the field data back into the entity field.
$custom_entity->custom_field->value = $custom_field_value;
// Save the entity.
$custom_entity->save();
Content entities examples
- node
- comment
- user
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion