How to do it...

  1. Let's create an Entity directory in our module's src folder. First, we will create an interface for our entity by creating a MessageInterface.php file:
  1. The MessageInterface will extend \Drupal\Core\Entity\ContentEntityInterface:
<?php 
 
namespace Drupal\mymodule\Entity; 
 
use Drupal\Core\Entity\ContentEntityInterface; 
 
interface MessageInterface extends ContentEntityInterface { 
 
  /** 
   * Gets the message value. 
   * 
   * @return string 
   */ 
  public function getMessage(); 
 
} 
 

This will be implemented by our entity and will provide the method requirements. It is best practice to provide an interface for entities. This allows you to provide ...

Get Drupal 8 Development Cookbook - 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.