private static function FieldEncryptEntityType::queueEntityUpdates in Field Encryption 3.0.x
Queues entity updates when entity is updated or deleted.
Parameters
string $entity_type_id: The ID of the entity being updated or deleted. This is the same as the entity type the config entity is configures.
2 calls to FieldEncryptEntityType::queueEntityUpdates()
- FieldEncryptEntityType::postDelete in src/
Entity/ FieldEncryptEntityType.php - Acts on deleted entities before the delete hook is invoked.
- FieldEncryptEntityType::postSave in src/
Entity/ FieldEncryptEntityType.php - Acts on a saved entity before the insert or update hook is invoked.
File
- src/
Entity/ FieldEncryptEntityType.php, line 148
Class
- FieldEncryptEntityType
- Defines the Field Encrypt entity type configuration entity.
Namespace
Drupal\field_encrypt\EntityCode
private static function queueEntityUpdates($entity_type_id) {
/** @var \Drupal\Core\Queue\QueueInterface $queue */
$queue = \Drupal::service('queue')
->get('field_encrypt_update_entity_encryption');
$entity_type_manager = \Drupal::entityTypeManager();
// Skip entity types that do not exist. This is defensive coding.
if ($entity_type_manager
->hasDefinition($entity_type_id) && $entity_type_manager
->getStorage($entity_type_id)
->hasData()) {
$entity_type = $entity_type_manager
->getDefinition($entity_type_id);
// Call the Queue API and add items for processing.
// Get entities that need updating, because they contain the field
// that has its field encryption settings updated.
$query = $entity_type_manager
->getStorage($entity_type_id)
->getQuery();
// Make sure to get all revisions for revisionable entities.
if ($entity_type
->isRevisionable()) {
$query
->allRevisions();
}
$entity_ids = $query
->execute();
$data = [
'entity_type' => $entity_type_id,
];
foreach (array_keys($entity_ids) as $entity_id) {
$data['entity_id'] = $entity_id;
$queue
->createItem($data);
}
\Drupal::messenger()
->addMessage(new TranslatableMarkup('Updates to @entity_type with existing data been queued to be processed. You should immediately <a href=":url">run this process manually</a>. Alternatively, the updates will be performed automatically by cron.', [
'@entity_type' => $entity_type
->getPluralLabel(),
':url' => Url::fromRoute('field_encrypt.process_queue')
->toString(),
]));
}
}