class ConstactStorageMaximumSubmissionsConstraintValidator in Contact Storage 8
Validates the maximum submission limit constraint.
Hierarchy
- class \Drupal\contact_storage\Plugin\Validation\Constraint\ConstactStorageMaximumSubmissionsConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of ConstactStorageMaximumSubmissionsConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ ConstactStorageMaximumSubmissionsConstraintValidator.php, line 11
Namespace
Drupal\contact_storage\Plugin\Validation\ConstraintView source
class ConstactStorageMaximumSubmissionsConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) {
// Check if the current user has reached the form's maximum submission limit.
$contact_form = $entity
->getParent()
->get('contact_form')
->referencedEntities()[0];
$maximum_submissions_user = $contact_form
->getThirdPartySetting('contact_storage', 'maximum_submissions_user', 0);
if ($maximum_submissions_user !== 0 && contact_storage_maximum_submissions_user($contact_form) >= $maximum_submissions_user) {
// Limit reached; can't submit the form.
$this->context
->addViolation($constraint->limitReached, [
'@limit' => $maximum_submissions_user,
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstactStorageMaximumSubmissionsConstraintValidator:: |
public | function | Checks if the passed value is valid. |