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:rebuild

Issue fork crm-3623033

Command icon 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

tommynin created an issue. See original summary.

bluegeek9’s picture

Issue summary: View changes

Thank you for reporting this bug.

bluegeek9’s picture

Status: Active » Needs review

  • bluegeek9 committed 06a5b31d on 1.0.x
    fix: #3623033  does not install  entity type definition
    
bluegeek9’s picture

Status: Needs review » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging CRM as a favorite on the project page to help others discover it and show your support.
  • Review the Developer Docs for accuracy and clarity.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

tommynin’s picture

Thank you for your wonderful module!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.