Custom content entity type

As we saw in the preceding chapter, when looking at the Node and NodeType entity types, entity type definitions belong inside the Entity folder of our module's namespace. In there, we will create a class called Product, which will have an annotation at the top to tell Drupal this is a content entity type. This is the most important part in defining a new entity type:

namespace Drupal\products\Entity;use Drupal\Core\Entity\ContentEntityBase;use Drupal\Core\Entity\EntityChangedTrait;use Drupal\Core\Entity\EntityTypeInterface;use Drupal\Core\Field\BaseFieldDefinition;/** * Defines the Product entity. * * @ContentEntityType( *   id = "product", *   label = @Translation("Product"), *   handlers = { * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.