ViewsBulkOperationsPassTestAction.php in Views Bulk Operations (VBO) 8.3
File
tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php
View source
<?php
namespace Drupal\views_bulk_operations_test\Plugin\Action;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase;
use Drupal\Core\Session\AccountInterface;
class ViewsBulkOperationsPassTestAction extends ViewsBulkOperationsActionBase {
use MessengerTrait;
public function executeMultiple(array $nodes) {
if (!empty($this->context['sandbox'])) {
$this
->messenger()
->addMessage(sprintf('Processed %s of %s.', $this->context['sandbox']['processed'], $this->context['sandbox']['total']));
}
if (empty($this->context['sandbox']['result_pass_error'])) {
$this->view->result = array_values($this->view->result);
foreach ($nodes as $index => $node) {
$result_node = $this->view->result[$index]->_entity;
if ($node
->id() !== $result_node
->id() || $node
->label() !== $result_node
->label()) {
$this->context['sandbox']['result_pass_error'] = TRUE;
}
}
}
$batch_size = isset($this->context['sandbox']['batch_size']) ? $this->context['sandbox']['batch_size'] : 0;
$total = isset($this->context['sandbox']['total']) ? $this->context['sandbox']['total'] : 0;
$processed = isset($this->context['sandbox']['processed']) ? $this->context['sandbox']['processed'] : 0;
if ($processed + $batch_size >= $total) {
if (empty($this->context['sandbox']['result_pass_error'])) {
$this
->messenger()
->addMessage('Passed view results match the entity queue.');
}
}
}
public function execute($entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return $object
->access('update', $account, $return_as_object);
}
}