public function OptionsLimitWebformHandler::validateBooleanElement in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php \Drupal\webform_options_limit\Plugin\WebformHandler\OptionsLimitWebformHandler::validateBooleanElement()
Validate a boolean element with limit(s).
Please note that this should never be called because disabled checkbox elements do not post back any value. This code would be executed if some one manually triggers for validation.
@internal This method should only called by OptionsLimitWebformHandler::validateElementLimit.
Parameters
array $element: A boolean element with limits.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- modules/
webform_options_limit/ src/ Plugin/ WebformHandler/ OptionsLimitWebformHandler.php, line 910
Class
- OptionsLimitWebformHandler
- Webform options and boolean (boolean) limit handler.
Namespace
Drupal\webform_options_limit\Plugin\WebformHandlerCode
public function validateBooleanElement(array $element, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformSubmissionForm $form_object */
$form_object = $form_state
->getFormObject();
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $form_object
->getEntity();
$this
->setWebformSubmission($webform_submission);
$element_key = $this->configuration['element_key'];
$original_value = $webform_submission
->getElementOriginalData($element_key);
$updated_value = $form_state
->getValue($element_key);
if (empty($updated_value) || !empty($original_value)) {
return;
}
$limit = $this->configuration['limit'];
$total = $this
->getBooleanTotal();
if ($total >= $limit) {
$limits = $this
->getBooleanLimits();
$message = $this
->getElementLimitStatusMessage(WebformOptionsLimitHandlerInterface::LIMIT_STATUS_ERROR, reset($limits));
$form_state
->setError($element, $message);
}
}