Example: Content Entity
Same name in other branches
- 3.x modules/content_entity_example/content_entity_example.module \content_entity_example
Implement a content entity.
This module demonstrates implementing a content entity.
Entity API is the API that stores pieces of content and configuration for Drupal core. For instance, if you've encountered node content types, you've encountered entities of type 'node.'
This example implements the Entity API so that we have an entity type usable by the user which you might think of as specialized nodes, but which are different from nodes. These entities are called Contact, and are known internally by the machine name content_entity_example_contact.
Contact is a fieldable content entity used to hold structured information without the overhead of using a node content type. 'Fieldable' means you can attach fields to it, like you can with nodes. It is defined programmatically (completely in code). We will show the main techniques to handle and expose the contents of this entity type.
The Contact entity will demonstrate the main tasks for an entity:
- define
- save
- load
- view
- edit
- delete
- control access
Where ever possible, we use the amazing tools built into D8 natively.
See also
Drupal\content_entity_example\Entity\Contact
Parent topics
File
-
modules/
content_entity_example/ content_entity_example.module, line 8
Classes
Title Sort descending | File name | Summary |
---|---|---|
Contact | modules/ |
Defines the ContentEntityExample entity. |
ContactDeleteForm | modules/ |
Provides a form for deleting a content_entity_example entity. |
ContactForm | modules/ |
Form controller for the content_entity_example entity edit forms. |
ContactListBuilder | modules/ |
Provides a list controller for content_entity_example entity. |
ContactSettingsForm | modules/ |
Class ContentEntityExampleSettingsForm. |
ContactTest | modules/ |
Test basic CRUD operations for our Contact entity type. |
ContentEntityExampleTest | modules/ |
Tests the basic functions of the Content Entity Example module. |
Interfaces
Title Sort descending | File name | Summary |
---|---|---|
ContactInterface | modules/ |
Provides an interface defining a Contact entity. |