You are here

public static function ViewsBulkOperationsBatch::getList in Views Bulk Operations (VBO) 8.3

Same name and namespace in other branches
  1. 8 src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::getList()
  2. 8.2 src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::getList()
  3. 4.0.x src/ViewsBulkOperationsBatch.php \Drupal\views_bulk_operations\ViewsBulkOperationsBatch::getList()

Gets the list of entities to process.

Used in "all results" batch operation.

Parameters

array $data: Processed view data.

array $context: Batch context.

3 calls to ViewsBulkOperationsBatch::getList()
drush_views_bulk_operations_execute in ./views_bulk_operations.drush.inc
The vbo-exec command execution function.
ViewsBulkOperationsCommands::vboExecute in src/Commands/ViewsBulkOperationsCommands.php
Execute an action on all results of the specified view.
ViewsBulkOperationsKernelTestBase::executeAction in tests/src/Kernel/ViewsBulkOperationsKernelTestBase.php
Execute an action on a specific view results.

File

src/ViewsBulkOperationsBatch.php, line 25

Class

ViewsBulkOperationsBatch
Defines module Batch API methods.

Namespace

Drupal\views_bulk_operations

Code

public static function getList(array $data, array &$context) {

  // Initialize batch.
  if (empty($context['sandbox'])) {
    $context['sandbox']['processed'] = 0;
    $context['sandbox']['page'] = 0;
    $context['sandbox']['total'] = $data['exclude_mode'] ? $data['total_results'] - count($data['exclude_list']) : $data['total_results'];
    $context['sandbox']['npages'] = ceil($data['total_results'] / $data['batch_size']);
    $context['results'] = $data;
  }
  $actionProcessor = \Drupal::service('views_bulk_operations.processor');
  $actionProcessor
    ->initialize($data);

  // Populate queue.
  $list = $actionProcessor
    ->getPageList($context['sandbox']['page']);
  $count = count($list);
  foreach ($list as $item) {
    $context['results']['list'][] = $item;
  }
  $context['sandbox']['page']++;
  $context['sandbox']['processed'] += $count;
  if ($context['sandbox']['page'] <= $context['sandbox']['npages']) {
    $context['finished'] = 0;
    $context['finished'] = $context['sandbox']['processed'] / $context['sandbox']['total'];
    $context['message'] = static::translate('Prepared @count of @total entities for processing.', [
      '@count' => $context['sandbox']['processed'],
      '@total' => $context['sandbox']['total'],
    ]);
  }
}