You are here

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

Same name and namespace in other branches
  1. 8.3 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.

1 call to ViewsBulkOperationsBatch::getList()
drush_views_bulk_operations_execute in ./views_bulk_operations.drush.inc
The vbo-exec command executtion function.

File

src/ViewsBulkOperationsBatch.php, line 40

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['results'] = $data;
  }
  $actionProcessor = \Drupal::service('views_bulk_operations.processor');
  $actionProcessor
    ->initialize($data);

  // Populate queue.
  $count = $actionProcessor
    ->populateQueue([], $context);
  if ($count) {
    foreach ($actionProcessor
      ->getQueue() as $index => $entity) {
      $item = [
        $index,
        $entity
          ->language()
          ->getId(),
        $entity
          ->getEntityTypeId(),
        $entity
          ->id(),
      ];
      $context['results']['list'][] = $item;
    }
    $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('Prepared @count of @total entities for processing.', [
        '@count' => $context['sandbox']['processed'],
        '@total' => $context['sandbox']['total'],
      ]);
    }
    else {
      $context['message'] = static::t('Prepared @count entities for processing.', [
        '@count' => $context['sandbox']['processed'],
      ]);
    }
  }
}