Creating a bundle for a content entity type
Bundles allow you to have different variations of a content entity. All bundles share the same base field definitions but not configured fields. This allows each bundle to have its own custom fields. Display modes are also dependent on a specific bundle. This allows each bundle to have its own configuration for the form mode and view mode.
Using the custom entity from the preceding recipe, we will add a configuration entity to act as the bundle. This will allow you to have different message types for multiple custom field configurations.
How to do it…
- Create a file named
MessageType.php
in thesrc/Entity
directory so that we can define theMessageType
class for our configuration entity type that will provide bundles for ourMessage
entity. - The
MessageType
class will extend the\Drupal\Core\Config\Entity\ConfigEntityBundleBase
class and define our entity type’s properties:<?php
namespace Drupal\mymodule\Entity...