O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required