protected function WebformSubmissionConditionsValidator::validateCondition in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionConditionsValidator.php \Drupal\webform\WebformSubmissionConditionsValidator::validateCondition()
Validate #state condition.
Parameters
string $selector: The #state condition selector.
array $condition: A condition.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
Return value
bool|null TRUE if the condition validates. NULL if condition can't be processed. NULL is returned when there is invalid selector and missing element in the conditions.
2 calls to WebformSubmissionConditionsValidator::validateCondition()
- WebformSubmissionConditionsValidator::replaceCrossPageTargets in src/
WebformSubmissionConditionsValidator.php - Replace hidden cross page targets with hidden inputs.
- WebformSubmissionConditionsValidator::validateConditions in src/
WebformSubmissionConditionsValidator.php - Validate #state conditions.
File
- src/
WebformSubmissionConditionsValidator.php, line 676
Class
- WebformSubmissionConditionsValidator
- Webform submission conditions (#states) validator.
Namespace
Drupal\webformCode
protected function validateCondition($selector, array $condition, WebformSubmissionInterface $webform_submission) {
// Ignore invalid selector and return NULL.
$input_name = static::getSelectorInputName($selector);
if (!$input_name) {
return NULL;
}
$element_key = static::getInputNameAsArray($input_name, 0);
$element = $webform_submission
->getWebform()
->getElement($element_key);
// If no element is found try checking file uploads which use
// :input[name="files[ELEMENT_KEY].
// @see \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getElementSelectorOptions
if (!$element && strpos($selector, ':input[name="files[') !== FALSE) {
$element_key = static::getInputNameAsArray($input_name, 1);
$element = $webform_submission
->getWebform()
->getElement($element_key);
}
// Ignore missing dependee element and return NULL.
if (!$element) {
return NULL;
}
// Issue #1149078: States API doesn't work with multiple select fields.
// @see https://www.drupal.org/project/drupal/issues/1149078
if (WebformArrayHelper::isSequential($condition)) {
$sub_condition_results = [];
foreach ($condition as $sub_condition) {
$sub_condition_results[] = $this
->checkCondition($element, $selector, $sub_condition, $webform_submission);
}
// Evaluate sub-conditions using the 'OR' operator.
return (bool) array_sum($sub_condition_results);
}
else {
return $this
->checkCondition($element, $selector, $condition, $webform_submission);
}
}