Error report generated by AI. Fix has not been checked. Workaround (as described at the bottom of the page) confirmed working.
Problem/Motivation
After upgrading `drupal/crm` to `1.0.0-beta12` on an existing site and running database updates (`drush updb`), the Status Report (`/admin/reports/status`) reports an entity definition mismatch error:
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Telephone Type
The Telephone Type entity type needs to be installed.
Cause
In `1.0.0-beta12` (task `#3615607`), the new configuration entity `crm_telephone_type` (`Drupal\crm\Entity\TelephoneType`) was introduced.
The post-update hook `crm_post_update_migrate_telephone_types()` in `crm.post_update.php` creates default config entities (`mobile` and `fax`) and migrates values from contact method details. However, it never registers the new entity type with Drupal's Entity Definition Update Manager:
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_manager->clearCachedDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$module_path = \Drupal::service('extension.list.module')->getPath('crm');
$config_storage = new FileStorage($module_path . '/config/install');
// Install default telephone type config if missing.
$telephone_type_storage = $entity_type_manager->getStorage('crm_telephone_type');
Because `\Drupal::entityDefinitionUpdateManager()->installEntityType(...)` is never called, Drupal's `entity.definitions.installed` key-value collection has no record of `crm_telephone_type`, triggering the definition mismatch warning.
---
Proposed Resolution
1. Update `crm_post_update_migrate_telephone_types()` in `crm.post_update.php` to install the entity type definition:
--- a/crm.post_update.php
+++ b/crm.post_update.php
@@ -287,6 +287,13 @@ function crm_post_update_migrate_telephone_types(): void {
$entity_type_manager->clearCachedDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
+ // Install the crm_telephone_type entity type definition if not installed.
+ $update_manager = \Drupal::entityDefinitionUpdateManager();
+ if ($update_manager->getEntityType('crm_telephone_type') === NULL) {
+ $update_manager->installEntityType($entity_type_manager->getDefinition('crm_telephone_type'));
+ }
+
$module_path = \Drupal::service('extension.list.module')->getPath('crm');
$config_storage = new FileStorage($module_path . '/config/install');
2. Add a new post-update hook (e.g., `crm_post_update_install_telephone_type_entity_type()`) so that sites that have already executed `crm_post_update_migrate_telephone_types()` will also have the entity type properly registered.
---
Workaround for Affected Sites
Sites currently experiencing this error can run the following Drush command to manually install the definition:
drush php:eval "\Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('crm_telephone_type'));"
drush cache:rebuildIssue fork crm-3623033
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bluegeek9 commentedThank you for reporting this bug.
Comment #4
bluegeek9 commentedComment #6
bluegeek9 commentedComment #8
tommynin commentedThank you for your wonderful module!