Creating a route provider

Entities can implement a route provider that will create the route definitions for the entity's canonical (view), edit, and delete routes. As of Drupal 8.0.1, the add path for an entity is not handled through the default route provider.

In this recipe, we will extend the default \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider and provide the add routes for our entity.

Getting ready

You will need a custom module to place the code into in order to implement a configuration entity type. Create an src directory for your classes. A custom content entity type needs to be implemented, such as the one in the Creating a content entity type recipe.

How to do it…

  1. Create a MessageHtmlRouteProvider class in the src directory that ...

Get Drupal 8 Development Cookbook now with O’Reilly online learning.

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