Created
October 9, 2023 04:12
-
-
Save back-2-95/1a4e94e236d690096790aeb897d61304 to your computer and use it in GitHub Desktop.
Drush script to fix mismatch entity and/or field definitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with:
drush scr path/to/fix-mismatch-entities.php