You are here

public function ViewsBulkOperationsActionProcessor::process in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::process()
  2. 8.2 src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::process()
  3. 4.0.x src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::process()

Process results.

Overrides ViewsBulkOperationsActionProcessorInterface::process

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

File

src/Service/ViewsBulkOperationsActionProcessor.php, line 283

Class

ViewsBulkOperationsActionProcessor
Defines VBO action processor.

Namespace

Drupal\views_bulk_operations\Service

Code

public function process() {
  $output = [];

  // Check if all queue items are actually Drupal entities.
  foreach ($this->queue as $delta => $entity) {
    if (!$entity instanceof EntityInterface) {
      $output[] = $this
        ->t('Skipped');
      unset($this->queue[$delta]);
    }
  }

  // Check entity type for multi-type views like search_api index.
  if (!empty($this->actionDefinition['type'])) {
    foreach ($this->queue as $delta => $entity) {
      if ($entity
        ->getEntityTypeId() !== $this->actionDefinition['type']) {
        $output[] = $this
          ->t('Entity type not supported');
        unset($this->queue[$delta]);
      }
    }
  }

  // Check access.
  foreach ($this->queue as $delta => $entity) {
    if (!$this->action
      ->access($entity, $this->user)) {
      $output[] = $this
        ->t('Access denied');
      unset($this->queue[$delta]);
    }
  }

  // Process queue.
  $results = $this->action
    ->executeMultiple($this->queue);

  // Populate output.
  if (empty($results)) {
    $count = count($this->queue);
    for ($i = 0; $i < $count; $i++) {
      $output[] = $this->bulkFormData['action_label'];
    }
  }
  else {
    foreach ($results as $result) {
      $output[] = $result;
    }
  }
  return $output;
}