drupal-console
drupal-console copied to clipboard
[generate:entity:config] SchemaIncompleteException on Drupal 9 when using generated config entities
[generate:entity:config] SchemaIncompleteException on Drupal 9 when using generated config entities
Problem/Motivation
Drupal 9 expects the annotation of a config entity to include a config_export key. See Change Record where this was initially introduced.
If you use the generate:entity:config
command, the annotation in the generated class file doesn't include the config_export key. This causes a SchemaIncompleteException when you try to add a configuration entity in the site admin UI.
How to reproduce
- Drupal 9.0.7
- Drupal Console version 1.9.5
- Drupal Console Launcher 1.9.4
- Create a Drupal site using a Composer template.
- Add Drupal Console using composer.
- Initialize the site and install Drupal.
- Create a sample module using
generate:module
and accepting all the defaults. - Create a config entity for the sample module using
generate:entity:config
and accepting all the defaults. - Enable the sample module and rebuild caches.
- In the site's admin UI, visit /admin/structure/default_entity (or the base path plus config entity name that you chose)
- Click the Add button.
- Fill in text for the Label field and click Save.
- The error message "The website encountered an unexpected error. Please try again later." is displayed.
- Visit /admin/reports/dblog and follow the link for the latest PHP error.
- Note the error message:
Drupal\Core\Config\Schema\SchemaIncompleteException: Entity type 'Drupal\Core\Config\Entity\ConfigEntityType' is missing 'config_export' definition in its annotation in Drupal\Core\Config\Entity\ConfigEntityBase->toArray() (line 251 of /web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php).
Solution
Add the following to the annotation in /modules/modulename/src/Entity/DefaultEntity.php:
* config_export = {
* "id",
* "label"
* },
The file template at /templates/module/src/Entity/entity.twig.php can be updated to include the config_export key in the annotation.
Hi, the solution works fine. Thank you!
Thank you for your contribution