public static function ViewsBulkOperationsBatch::operation in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::operation()
- 8.2 src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::operation()
- 4.0.x src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::operation()
Batch operation callback.
Parameters
array $data: Processed view data.
array $context: Batch context.
1 call to ViewsBulkOperationsBatch::operation()
- drush_views_bulk_operations_execute in ./
views_bulk_operations.drush.inc - The vbo-exec command executtion function.
File
- src/
ViewsBulkOperationsBatch.php, line 113
Class
- ViewsBulkOperationsBatch
- Defines module Batch API methods.
Namespace
Drupal\views_bulk_operationsCode
public static function operation(array $data, array &$context) {
// Initialize batch.
if (empty($context['sandbox'])) {
$context['sandbox']['processed'] = 0;
$context['results']['operations'] = [];
}
// Get entities to process.
$actionProcessor = \Drupal::service('views_bulk_operations.processor');
$actionProcessor
->initialize($data);
// Do the processing.
$count = $actionProcessor
->populateQueue($data['list'], $context);
if ($count) {
$batch_results = $actionProcessor
->process();
if (!empty($batch_results)) {
// Convert translatable markup to strings in order to allow
// correct operation of array_count_values function.
foreach ($batch_results as $result) {
$context['results']['operations'][] = (string) $result;
}
}
$context['sandbox']['processed'] += $count;
$context['finished'] = 0;
// There may be cases where we don't know the total number of
// results (e.g. mini pager with a search_api view)
if ($context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['processed'] / $context['sandbox']['total'];
$context['message'] = static::t('Processed @count of @total entities.', [
'@count' => $context['sandbox']['processed'],
'@total' => $context['sandbox']['total'],
]);
}
else {
$context['message'] = static::t('Processed @count entities.', [
'@count' => $context['sandbox']['processed'],
]);
}
}
}