Based on requirements of a couple projects that I am currently working on, I was in the need to create a content entity type in Drupal 8, and as usual I decided to go ahead and do what every developer does, RTFM and follow the steps as shown on the official documentation.
I was lucky enough to found a link related to my task “Creating a content entity type in Drupal 8” on the official documentation but since code on a project at Alpha state changes a lot the documentation was not up to date, it means the official documentation is the code and as you can guess I faced some challenges that I will list below and the approach I used to overcome it.
The "foo_bar" entity type did not specify a list_builder class
After installing the module and trying to visit the route "foo-bar/list" the following error was triggered.
Uncaught PHP Exception Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException:
"The "foo_bar" entity type did not specify a list_builder class." at
/core/lib/Drupal/Core/Entity/EntityManager.php line 293
Fix: Replace on "src/Entity/FooBar.php" class at the plugin controllers declaration "list" with "list_builder" and since "FooBarListController" class does not exist, point it to the correct class "FooBarListBuilder"
When trying to add new content using the follwing route "foo-bar/add" the following error was triggered
PHP Fatal error: Class 'Drupal\Core\Entity\ContentEntityFormController'
not found in /modules/foo_bar/src/Entity/Form/FooBarFormController.php
on line 12
Fix: "ContentEntityFormController" class not longer exist it was repalced with "ContentEntityForm" then the next step was to replace it on "FooBarFormController" class
Feel free to send any corrections, improvements or comments related to the new code.
We are CMS specialist and Headless is our passion
Our team has several years of experience working with traditional CMS as Drupal and Wordpress and more than a couple of years using those systems as Headless CMS and providing integrations with modern front-end tools as GatsbyJS, NextJS and others.