public function WebformSubmissionConditionsValidator::isElementVisible in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionConditionsValidator.php \Drupal\webform\WebformSubmissionConditionsValidator::isElementVisible()
Determine if an element is visible.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
Return value
bool TRUE if the element is visible.
Overrides WebformSubmissionConditionsValidatorInterface::isElementVisible
1 call to WebformSubmissionConditionsValidator::isElementVisible()
- WebformSubmissionConditionsValidator::submitFormRecursive in src/
WebformSubmissionConditionsValidator.php - Recursively unset submission data for form elements that are hidden.
File
- src/
WebformSubmissionConditionsValidator.php, line 499
Class
- WebformSubmissionConditionsValidator
- Webform submission conditions (#states) validator.
Namespace
Drupal\webformCode
public function isElementVisible(array $element, WebformSubmissionInterface $webform_submission) {
$states = WebformElementHelper::getStates($element);
$visible = TRUE;
foreach ($states as $state => $conditions) {
if (!is_array($conditions)) {
continue;
}
// Process state/negate.
list($state, $negate) = $this
->processState($state);
$result = $this
->validateConditions($conditions, $webform_submission);
// Skip invalid conditions.
if ($result === NULL) {
continue;
}
// Negate the result.
$result = $negate ? !$result : $result;
// Apply result to element state.
if (strpos($state, 'visible') === 0 && $result === FALSE) {
$visible = FALSE;
}
}
return $visible;
}