You are here

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

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

Batch builder function.

Parameters

array $view_data: Processed view data.

1 call to ViewsBulkOperationsBatch::getBatch()
ViewsBulkOperationsActionProcessor::executeProcessing in src/Service/ViewsBulkOperationsActionProcessor.php
Helper function for processing results from view data.

File

src/ViewsBulkOperationsBatch.php, line 134

Class

ViewsBulkOperationsBatch
Defines module Batch API methods.

Namespace

Drupal\views_bulk_operations

Code

public static function getBatch(array &$view_data) {
  $current_class = get_called_class();

  // Prepopulate results.
  if (empty($view_data['list'])) {

    // Redirect this batch to the processing URL and set
    // previous redirect under a different key for later use.
    $view_data['redirect_after_processing'] = $view_data['redirect_url'];
    $view_data['redirect_url'] = Url::fromRoute('views_bulk_operations.execute_batch', [
      'view_id' => $view_data['view_id'],
      'display_id' => $view_data['display_id'],
    ]);
    $batch = [
      'title' => static::translate('Prepopulating entity list for processing.'),
      'operations' => [
        [
          [
            $current_class,
            'getList',
          ],
          [
            $view_data,
          ],
        ],
      ],
      'progress_message' => static::translate('Prepopulating, estimated time left: @estimate, elapsed: @elapsed.'),
      'finished' => [
        $current_class,
        'saveList',
      ],
    ];
  }
  else {
    $batch = [
      'title' => static::translate('Performing @operation on selected entities.', [
        '@operation' => $view_data['action_label'],
      ]),
      'operations' => [
        [
          [
            $current_class,
            'operation',
          ],
          [
            $view_data,
          ],
        ],
      ],
      'progress_message' => static::translate('Processing, estimated time left: @estimate, elapsed: @elapsed.'),
      'finished' => $view_data['finished_callback'],
    ];
  }
  return $batch;
}