Skip to content

Instantly share code, notes, and snippets.

@back-2-95
Created October 9, 2023 04:12
Show Gist options
  • Save back-2-95/1a4e94e236d690096790aeb897d61304 to your computer and use it in GitHub Desktop.
Save back-2-95/1a4e94e236d690096790aeb897d61304 to your computer and use it in GitHub Desktop.
Drush script to fix mismatch entity and/or field definitions
<?php
/**
* @file
* Fix mismatch entity and/or field definitions.
*/
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_manager->clearCachedDefinitions();
$entity_type_ids = [];
$change_summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary();
foreach ($change_summary as $entity_type_id => $change_list) {
$entity_type = $entity_type_manager->getDefinition($entity_type_id);
\Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
$entity_type_ids[] = $entity_type_id;
}
if (count($entity_type_ids)) {
echo t("Installed/Updated the entity type(s): @entity_type_ids", [
'@entity_type_ids' => implode(', ', $entity_type_ids),
]) . PHP_EOL;
}
else {
echo t("[OK] No entity types were installed/updated.") . PHP_EOL;
}
@back-2-95
Copy link
Author

Run with:

drush scr path/to/fix-mismatch-entities.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment