Configuration entity vs Content entity in Drupal
What is Entity?
Entities are usually recognizable concepts. For ex-employee of an organization such as persons, places, things, or events that have relevance to the database.
- Entities in Drupal provide a structured way of storing and managing data.
- Several types of entities included in Drupal core makeup both the configuration and content of a default installation.
- Entities are specifically typed objects, with each entity type defining a class that will be used for instances of the given entity.
- Drupal entities are node (content), taxonomy term, user, comments, block, file, imagestyle.
- Consistent way to access field values.
$nodeStorage = \Drupal::entityTypeManager()->getStorage(‘node’);$node = $nodeStorage->load($nid);print_r($node->get(‘field_name’)->getValue());
Content entity vs Configuration Entity
Content entity
- A content entity is an item of content data, consisting of text, HTML markup, images, attached files, and other data intended to be displayed to site visitors.
- Content entities are grouped into entity types, which have different purposes and are displayed in very different ways on the site.
- Content Entities Stores data inside table.
Examples of Content Entities
- Block content
- Comment
- Message
- File
- Menu Link
- Content (node)
- Shortcut
- Taxonomy term
- User
How to create Content Entity
Lets Create a Custom Entity having the following fields :
- Name
- Contact number
Use command
- drupal geco – created a custom Content Entity
Then Adding field in (entityname).php File
How it look’s in Admin
After saving a content entity a entry will generate
Stored data in a database (in rows)
Configuration Entity
- They are objects that allow to storage information for configurable settings.
- Configuration entities can be exported via a configuration management system.
- It is stored within the common config database table as rows. eg: image style.
- Stores data inside the object
Examples of Configuration Entities
- Action
- Block
- Breakpoints
- Comment Type
- Content Type
- Date Format
- Field
- Image Style
- Language
- Menu
- Role
- Views
How to Create a Configuration Entity
Let’s Create Config Entity to configure settings for an API like
- endpoint
- access key
- secret key
Using Drupal gec – created a config Entity
Fields
How it look’s in Admin
After saving a Configuration entity, it will only show a message (created/saved), not its field entry.
Stored data in a database (In Object)
How it’s object look like