Custom content entity type

As we saw in the previous 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;/** * Defines the Product entity. * * @ContentEntityType( *   id = "product", *   label = @Translation("Product"), *   handlers = { *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", *     "list_builder" = "Drupal\products\ProductListBuilder", * *     "form" = { * "default" = "Drupal\products\Form\ProductForm", ...

Get Drupal 8 Module Development - Second Edition 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.