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:
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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.