protected function WebformSubmissionConditionsValidator::checkConditionTrigger in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionConditionsValidator.php \Drupal\webform\WebformSubmissionConditionsValidator::checkConditionTrigger()
Process condition trigger.
Parameters
string $trigger: The trigger.
string $trigger_value: The trigger value.
string|array $element_value: The element value.
Return value
bool|null The result.
1 call to WebformSubmissionConditionsValidator::checkConditionTrigger()
- WebformSubmissionConditionsValidator::checkCondition in src/
WebformSubmissionConditionsValidator.php - Check a condition.
File
- src/
WebformSubmissionConditionsValidator.php, line 792
Class
- WebformSubmissionConditionsValidator
- Webform submission conditions (#states) validator.
Namespace
Drupal\webformCode
protected function checkConditionTrigger($trigger, $trigger_value, $element_value) {
// Process triggers (aka remote conditions).
// @see \Drupal\webform\Element\WebformElementStates::processWebformStates
switch ($trigger) {
case 'empty':
$empty = empty($element_value) && $element_value !== '0';
return $empty === (bool) $trigger_value;
case 'checked':
return (bool) $element_value === (bool) $trigger_value;
case 'value':
return (string) $element_value === (string) $trigger_value;
case 'pattern':
// PHP: Convert JavaScript-escaped Unicode characters to PCRE
// escape sequence format.
// @see \Drupal\webform\Plugin\WebformElement\TextBase::validatePattern
$pcre_pattern = preg_replace('/\\\\u([a-fA-F0-9]{4})/', '\\x{\\1}', $trigger_value);
return preg_match('{' . $pcre_pattern . '}u', $element_value);
case 'less':
return $element_value !== '' && floatval($trigger_value) > floatval($element_value);
case 'less_equal':
return $element_value !== '' && floatval($trigger_value) >= floatval($element_value);
case 'greater':
return $element_value !== '' && floatval($trigger_value) < floatval($element_value);
case 'greater_equal':
return $element_value !== '' && floatval($trigger_value) <= floatval($element_value);
case 'between':
if ($element_value === '') {
return NULL;
}
$greater = NULL;
$less = NULL;
if (strpos($trigger_value, ':') === FALSE) {
$greater = $trigger_value;
}
else {
list($greater, $less) = explode(':', $trigger_value);
}
$is_greater_than = $greater === NULL || $greater === '' || floatval($element_value) >= floatval($greater);
$is_less_than = $less === NULL || $less === '' || floatval($element_value) <= floatval($less);
return $is_greater_than && $is_less_than;
default:
return NULL;
}
}