You are here

public function YamlFormSubmissionStorage::deleteAll in YAML Form 8

Delete all form submissions.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: (optional) The form to delete the submissions from.

\Drupal\Core\Entity\EntityInterface|null $source_entity: (optional) A form submission source entity.

int $limit: (optional) Number of submissions to be deleted.

int $max_sid: (optional) Maximum form submission id.

Return value

int The number of form submissions deleted.

Overrides YamlFormSubmissionStorageInterface::deleteAll

File

src/YamlFormSubmissionStorage.php, line 96

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function deleteAll(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, $limit = NULL, $max_sid = NULL) {
  $query = $this
    ->getQuery()
    ->sort('sid');
  if ($yamlform) {
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
  }
  if ($source_entity) {
    $query
      ->condition('entity_type', $source_entity
      ->getEntityTypeId());
    $query
      ->condition('entity_id', $source_entity
      ->id());
  }
  if ($limit) {
    $query
      ->range(0, $limit);
  }
  if ($max_sid) {
    $query
      ->condition('sid', $max_sid, '<=');
  }
  $entity_ids = $query
    ->execute();
  $entities = $this
    ->loadMultiple($entity_ids);
  $this
    ->delete($entities);
  return count($entities);
}