function system_update_8702 in Drupal 8
Add the 'revision_translation_affected' entity key.
File
- core/
modules/ system/ system.install, line 2600 - Install, update and uninstall functions for the system module.
Code
function system_update_8702() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Get a list of revisionable and translatable entity types.
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $last_installed_definitions */
$last_installed_definitions = array_filter($entity_definition_update_manager
->getEntityTypes(), function (EntityTypeInterface $entity_type) {
return $entity_type
->isRevisionable() && $entity_type
->isTranslatable();
});
// Ensure that we don't use the cached in-code definitions to support sites
// that might be updating from 8.3.x straight to 8.7.x.
\Drupal::entityTypeManager()
->useCaches(FALSE);
$live_definitions = \Drupal::entityTypeManager()
->getDefinitions();
// Update the 'revision_translation_affected' entity key of the last installed
// definitions to use the value of the live (in-code) entity type definitions
// in cases when the key has not been populated yet.
foreach ($last_installed_definitions as $entity_type_id => $entity_type) {
// The live (in-code) entity type definition might not exist anymore, while
// an update function that would remove its last installed definition didn't
// run yet. We don't need to update it in that case.
if (!isset($live_definitions[$entity_type_id])) {
continue;
}
$revision_translation_affected_key = $live_definitions[$entity_type_id]
->getKey('revision_translation_affected');
if (!$entity_type
->hasKey('revision_translation_affected') && !empty($revision_translation_affected_key) && $entity_definition_update_manager
->getFieldStorageDefinition($revision_translation_affected_key, $entity_type_id)) {
$entity_keys = $entity_type
->getKeys();
$entity_keys['revision_translation_affected'] = $revision_translation_affected_key;
$entity_type
->set('entity_keys', $entity_keys);
$entity_definition_update_manager
->updateEntityType($entity_type);
}
}
\Drupal::entityTypeManager()
->useCaches(TRUE);
}