protected function ViewsBulkOperationsKernelTestBase::executeAction in Views Bulk Operations (VBO) 8.2
Same name and namespace in other branches
- 8.3 tests/src/Kernel/ViewsBulkOperationsKernelTestBase.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase::executeAction()
- 4.0.x tests/src/Kernel/ViewsBulkOperationsKernelTestBase.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase::executeAction()
Execute an action on a specific view results.
Parameters
array $vbo_data: An array of data passed to VBO Processor service.
1 call to ViewsBulkOperationsKernelTestBase::executeAction()
- ViewsBulkOperationsActionProcessorTest::testViewsbulkOperationsActionProcessor in tests/
src/ Kernel/ ViewsBulkOperationsActionProcessorTest.php - Tests general functionality of ViewsBulkOperationsActionProcessor.
File
- tests/
src/ Kernel/ ViewsBulkOperationsKernelTestBase.php, line 243
Class
- ViewsBulkOperationsKernelTestBase
- Base class for Views Bulk Operations kernel tests.
Namespace
Drupal\Tests\views_bulk_operations\KernelCode
protected function executeAction(array $vbo_data) {
// Merge in defaults.
$vbo_data += static::VBO_DEFAULTS;
$view = $this
->initializeView($vbo_data);
$view->get_total_rows = TRUE;
$view
->execute();
// Get total rows count.
$this->vboDataService
->init($view, $view
->getDisplay(), $vbo_data['relationship_id']);
$vbo_data['total_results'] = $this->vboDataService
->getTotalResults();
// Get action definition and check if action ID is correct.
$action_definition = $this->container
->get('plugin.manager.views_bulk_operations_action')
->getDefinition($vbo_data['action_id']);
if (!isset($vbo_data['action_label'])) {
$vbo_data['action_label'] = (string) $action_definition['label'];
}
// Populate entity list if empty.
if (empty($vbo_data['list'])) {
$context = [];
do {
$context['finished'] = 1;
$context['message'] = '';
ViewsBulkOperationsBatch::getList($vbo_data, $context);
} while ($context['finished'] < 1);
$vbo_data = $context['results'];
}
$summary = [
'messages' => [],
];
// Execute the selected action.
$context = [];
do {
$context['finished'] = 1;
$context['message'] = '';
ViewsBulkOperationsBatch::operation($vbo_data, $context);
if (!empty($context['message'])) {
$summary['messages'][] = (string) $context['message'];
}
} while ($context['finished'] < 1);
// Add information to the summary array.
$summary += [
'operations' => array_count_values($context['results']['operations']),
];
return $summary;
}