protected function WebformSubmissionForm::checkUserLimit in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::checkUserLimit()
Check webform submission user limit.
Return value
bool TRUE if webform submission user limit have been met.
2 calls to WebformSubmissionForm::checkUserLimit()
- 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 2819
Class
- WebformSubmissionForm
- Provides a webform to collect and edit submissions.
Namespace
Drupal\webformCode
protected function checkUserLimit() {
// Allow anonymous and authenticated users edit own submission.
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $this
->getEntity();
if ($webform_submission
->id() && $webform_submission
->isOwner($this
->currentUser())) {
return FALSE;
}
// Get the submission owner and not current user.
// This takes into account when an API submission changes the owner id.
// @see \Drupal\webform\WebformSubmissionForm::submitFormValues
$account = $this->entity
->getOwner();
$webform = $this
->getWebform();
// Check per source entity user limit.
$entity_limit_user = $this
->getWebformSetting('entity_limit_user');
$entity_limit_user_interval = $this
->getWebformSetting('entity_limit_user_interval');
if ($entity_limit_user && ($source_entity = $this
->getLimitSourceEntity())) {
if ($this
->getStorage()
->getTotal($webform, $source_entity, $account, [
'interval' => $entity_limit_user_interval,
]) >= $entity_limit_user) {
return TRUE;
}
}
// Check user limit.
$limit_user = $this
->getWebformSetting('limit_user');
$limit_user_interval = $this
->getWebformSetting('limit_user_interval');
if ($limit_user && $this
->getStorage()
->getTotal($webform, NULL, $account, [
'interval' => $limit_user_interval,
]) >= $limit_user) {
return TRUE;
}
return FALSE;
}