You are here

public function YamlFormSubmissionsDeleteFormBase::batchProcess in YAML Form 8

Batch API callback; Delete submissions.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: The form.

\Drupal\Core\Entity\EntityInterface|null $entity: The form's source entity.

int $max_sid: The max submission ID to be delete.

mixed|array $context: The batch current context.

File

src/Form/YamlFormSubmissionsDeleteFormBase.php, line 164

Class

YamlFormSubmissionsDeleteFormBase
Base form for deleting form submission.

Namespace

Drupal\yamlform\Form

Code

public function batchProcess(YamlFormInterface $yamlform = NULL, EntityInterface $entity = NULL, $max_sid, &$context) {

  // ISSUE:
  // $this->submissionStorage is not being setup via
  // YamlFormSubmissionsDeleteFormBase::__construct.
  //
  // WORKAROUND:
  // Reset it for each batch process.
  $this->submissionStorage = \Drupal::entityTypeManager()
    ->getStorage('yamlform_submission');
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = $this->submissionStorage
      ->getTotal($yamlform, $entity);
    $context['results']['yamlform'] = $yamlform;
    $context['results']['entity'] = $entity;
  }

  // Track progress.
  $context['sandbox']['progress'] += $this->submissionStorage
    ->deleteAll($yamlform, $entity, $this
    ->getBatchLimit(), $max_sid);
  $context['message'] = $this
    ->t('Deleting @count of @total submissions...', [
    '@count' => $context['sandbox']['progress'],
    '@total' => $context['sandbox']['max'],
  ]);

  // Track finished.
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}