Commit 9242b773 authored by Marcin Grabias's avatar Marcin Grabias
Browse files

Issue #3210957 by alvar0hurtad0, liquidcms, mikran: VBO is skipping translated...

Issue #3210957 by alvar0hurtad0, liquidcms, mikran: VBO is skipping translated entities during batch process
parent 21c6d1d2
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -305,7 +305,9 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro
      $batch_list = $list;
    }

    $this->view->setItemsPerPage($batch_size);
    // Note: this needs to be set to 0 because otherwise we may lose
    // entity translations from the results.
    $this->view->setItemsPerPage(0);
    $this->view->setCurrentPage(0);
    $this->view->setOffset(0);
    $this->view->initHandlers();
@@ -327,7 +329,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro
    // Modify the view query: determine and apply the base field condition.
    $base_field_values = [];
    foreach ($batch_list as $item) {
      $base_field_values[] = $item[0];
      $base_field_values[$item[0]] = $item[0];
    }
    if (empty($base_field_values)) {
      return 0;
@@ -368,22 +370,22 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro
    // Get entities.
    $this->viewDataService->init($this->view, $this->view->getDisplay(), $this->bulkFormData['relationship_id']);

    // Get all the entities in the batch_list from the view.
    // Check labnguage as well as the query will fetch results basing on
    // base ID field for all languages.
    $result_hits = [];
    foreach ($batch_list as $delta => $item) {
      foreach ($this->view->result as $row_index => $row) {
      // This may return rows for all possible languages.
      // Check if the current language is on the list.
      $found = FALSE;
        if (array_key_exists($row_index, $result_hits)) {
          continue;
        }
        $entity = $this->viewDataService->getEntity($row);
      foreach ($batch_list as $delta => $item) {
        if ($row->{$base_field} === $item[0] && $entity->language()->getId() === $item[1]) {
          $result_hits[$row_index] = TRUE;
          $this->queue[] = $entity;
          $found = TRUE;
          unset($batch_list[$delta]);
          break;
        }
      }
      if (!$found) {
        unset($this->view->result[$row_index]);
      }
    }

    // Extra processing when executed in a Batch API operation.