You are here

Example: Content Entity in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 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

Example: Config Entity

Parent topics

File

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

Classes

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

Interfaces

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