public static function NodeRevisionDeleteBatch::finish in Node Revision Delete 8
Actions on finishing the batch.
Parameters
bool $success: The flag to identify if batch has successfully run or not.
array $results: The results from running context.
array $operations: The array of operations remained unprocessed.
File
- src/
NodeRevisionDeleteBatch.php, line 65
Class
- NodeRevisionDeleteBatch
- Methods for delete revisions in a batch.
Namespace
Drupal\node_revision_deleteCode
public static function finish($success, array $results, array $operations) {
$messenger = \Drupal::messenger();
$logger = \Drupal::logger('node_revision_delete');
if ($success) {
// If we are finishing the prior delete feature.
if (isset($context['results']['node'])) {
$variables = [
'@total' => $results['revisions'],
'@type' => $results['node']->type->entity
->label(),
'@title' => $results['node']
->label(),
];
$success_message = \Drupal::translation()
->formatPlural($results['revisions'], 'One prior revision deleted.', '@count prior revisions deleted of @type <em>@title</em>', $variables);
}
else {
$success_message = \Drupal::translation()
->formatPlural($results['revisions'], 'One revision has been deleted.', 'Deleted @count revisions.', [
'@total' => $results['revisions'],
]);
}
$logger
->notice($success_message);
$messenger
->addMessage($success_message);
}
else {
// An error occurred.
// $operations contains the operations that remained unprocessed.
$error_operation = reset($operations);
$message = t('An error occurred while processing %error_operation with arguments: @arguments', [
'%error_operation' => $error_operation[0],
'@arguments' => print_r($error_operation[1], TRUE),
]);
$logger
->error($message);
$messenger
->addError($message);
}
}