Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generate:entity:config] SchemaIncompleteException on Drupal 9 when using generated config entities #4280

Closed
cboyden opened this issue Nov 4, 2020 · 2 comments · Fixed by #4281

Comments

@cboyden
Copy link
Contributor

cboyden commented Nov 4, 2020

[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
  1. Create a Drupal site using a Composer template.
  2. Add Drupal Console using composer.
  3. Initialize the site and install Drupal.
  4. Create a sample module using generate:module and accepting all the defaults.
  5. Create a config entity for the sample module using generate:entity:config and accepting all the defaults.
  6. Enable the sample module and rebuild caches.
  7. In the site's admin UI, visit /admin/structure/default_entity (or the base path plus config entity name that you chose)
  8. Click the Add button.
  9. Fill in text for the Label field and click Save.
  10. The error message "The website encountered an unexpected error. Please try again later." is displayed.
  11. Visit /admin/reports/dblog and follow the link for the latest PHP error.
  12. 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.

@finex
Copy link

finex commented Sep 24, 2021

Hi, the solution works fine. Thank you!

@LOBsTerr
Copy link
Member

Thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants