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

Example: Config Entity

Parent topics

File

content_entity_example/content_entity_example.module, line 8
Contains Drupal\content_entity_example\content_entity_example.module.

Classes

Namesort descending Location Description
Contact content_entity_example/src/Entity/Contact.php Defines the ContentEntityExample entity.
ContactDeleteForm content_entity_example/src/Form/ContactDeleteForm.php Provides a form for deleting a content_entity_example entity.
ContactForm content_entity_example/src/Form/ContactForm.php Form controller for the content_entity_example entity edit forms.
ContactListBuilder content_entity_example/src/Entity/Controller/ContactListBuilder.php Provides a list controller for content_entity_example entity.
ContactSettingsForm content_entity_example/src/Form/ContactSettingsForm.php Class ContentEntityExampleSettingsForm.
ContactTest content_entity_example/tests/src/Kernel/ContactTest.php Test basic CRUD operations for our Contact entity type.
ContentEntityExampleTest content_entity_example/tests/src/Functional/ContentEntityExampleTest.php Tests the basic functions of the Content Entity Example module.

Interfaces

Namesort descending Location Description
ContactInterface content_entity_example/src/ContactInterface.php Provides an interface defining a Contact entity.