Mismatched Entity Error

Submitted by Tom Thorp on Monday, November 4, 2019 - 23:06
Modified on Thursday, November 7, 2019 - 01:10
Mismatched Entity Error
I noticed the 'Mismatched entity' error in my status screen, after I performed an update to Drupal 8.7.7 . Although it didn't adversely affect the running of my website, it was an error that wasn't going to go away. So I was determined to find a solution.
 

Solution

The solution in my instance, related to the GoogleTagManager module . According to the issue queue, the problem is described as follows :
"Drupal prefers each entity_type to be officially 'installed' which simply means entity type listeners are given an opportunity to act on the new arrival. Afterwards, the entity type is recorded in the database. Absent this 'install' action, the status report page (at 'admin/reports/status') will include an 'error' indicating the 'entity type needs to be installed'."
At time of writing, the current release of GoogleTagManager module was v8.x-1.2 . With this release, GoogleTagManager now allows for multiple containers per page request. However, the module is missing the following code in 'google_tag.install' to make the module compliant.
/**
 * Install the container configuration entity type.
 */
function google_tag_update_8102(&$sandbox) {
  $type_manager = \Drupal::entityTypeManager();
  $type_manager->clearCachedDefinitions();
  $entity_type = $type_manager->getDefinition('google_tag_container');
  \Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);

  return t('Installed the google_tag_container entity type');
}
To add this code, you can either copy the code to the end of 'google_tag.install', or install the development version of the module (which contains the additional code). Then, simply run a database update to commit the entity type to the database.
 
The above code will be incorporated into v8.x-1.3 when it is released.
 
 

About the author

Tom Thorp
Tom Thorp is an IT Consultant living in Miami on Queensland's Gold Coast. With over 30+ years working in the IT industry, Tom's experience is a broad canvas. The IT services Tom provides to his clients, includes :
 
Website development and hosting
Database Administration
Server Administration (Windows, Linux, Apple)
PABX Hosting and Administration
Helpdesk Support (end-user & technical).
  If you like any of my content, consider a donation via Crypto by clicking on one of the payment methods :
 
Categories