public function StateManager::update in Field Encryption 3.0.x
Figure out which entity types are encrypted.
File
- src/
StateManager.php, line 95
Class
- StateManager
- Manages state for the module.
Namespace
Drupal\field_encryptCode
public function update() {
$old_entity_types = $this->state
->get('field_encrypt.entity_types', []);
$new_entity_types = $this
->getEntityTypes();
if ($old_entity_types === $new_entity_types) {
// No changes to make. Early return to do nothing and preserve caches.
return;
}
// Get entities where we need to add a field.
foreach (array_diff($new_entity_types, $old_entity_types) as $type) {
$definition = static::getEncryptedFieldStorageDefinition();
$this->entityDefinitionUpdateManager
->installFieldStorageDefinition(ProcessEntities::ENCRYPTED_FIELD_STORAGE_NAME, $type, 'field_encrypt', $definition);
}
// We can't remove the field if there are queue items to process because if
// there is data we'll destroy it. So merge in the old entity types.
$this->state
->set('field_encrypt.entity_types', array_merge($old_entity_types, $new_entity_types));
// @see field_encrypt.module
$this->moduleHandler
->resetImplementations();
// @see field_encrypt_entity_type_alter()
$this->entityTypeManager
->clearCachedDefinitions();
$this
->setEntityTypeCacheInformation($new_entity_types);
}