Creating a content entity type
Content entities provide base field definitions and configurable fields with the Field UI module. There is also support for revisions and translations with content entities. Display modes, both form and view, are available for content entities to control how the fields are edited and displayed. When an entity does not specify bundles, there is automatically one bundle instance with the same name as the entity.
In this recipe, we will create a custom content entity that does not specify a bundle. We will create a Message entity that can serve as a content entity for generic messages.
How to do it…
- First, we need to create the
src/Entity
directory in the module’s directory. This will translate to the\Drupal\mymodule\Entity
namespace and allow for entity type discovery:mkdir -p src/Entity
- Create a file named
Message.php
in the newly created directory so that we can define theMessage
class for our entity type. - The
Message...