You are here

protected function WebformSubmissionForm::checkTotalLimit in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::checkTotalLimit()

Check webform submission total limits.

Return value

bool TRUE if webform submission total limit have been met.

2 calls to WebformSubmissionForm::checkTotalLimit()
WebformSubmissionForm::getCustomForm in src/WebformSubmissionForm.php
Get custom webform which is displayed instead of the webform's elements.
WebformSubmissionForm::save in src/WebformSubmissionForm.php
Form submission handler for the 'save' action.

File

src/WebformSubmissionForm.php, line 2780

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function checkTotalLimit() {
  $webform = $this
    ->getWebform();

  // Get limit total to unique submission per webform/source entity.
  $limit_total_unique = $this
    ->getWebformSetting('limit_total_unique');

  // Check per source entity total limit.
  $entity_limit_total = $this
    ->getWebformSetting('entity_limit_total');
  $entity_limit_total_interval = $this
    ->getWebformSetting('entity_limit_total_interval');
  if ($limit_total_unique) {
    $entity_limit_total = 1;
    $entity_limit_total_interval = NULL;
  }
  if ($entity_limit_total && ($source_entity = $this
    ->getLimitSourceEntity())) {
    if ($this
      ->getStorage()
      ->getTotal($webform, $source_entity, NULL, [
      'interval' => $entity_limit_total_interval,
    ]) >= $entity_limit_total) {
      return TRUE;
    }
  }

  // Check total limit.
  $limit_total = $this
    ->getWebformSetting('limit_total');
  $limit_total_interval = $this
    ->getWebformSetting('limit_total_interval');
  if ($limit_total_unique) {
    $limit_total = 1;
    $limit_total_interval = NULL;
  }
  if ($limit_total && $this
    ->getStorage()
    ->getTotal($webform, NULL, NULL, [
    'interval' => $limit_total_interval,
  ]) >= $limit_total) {
    return TRUE;
  }
  return FALSE;
}