public function WebformSubmissionConditionsValidator::isElementEnabled in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionConditionsValidator.php \Drupal\webform\WebformSubmissionConditionsValidator::isElementEnabled()
Determine if an element is enabled.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
Return value
bool TRUE if the element is enabled.
Overrides WebformSubmissionConditionsValidatorInterface::isElementEnabled
File
- src/
WebformSubmissionConditionsValidator.php, line 532
Class
- WebformSubmissionConditionsValidator
- Webform submission conditions (#states) validator.
Namespace
Drupal\webformCode
public function isElementEnabled(array $element, WebformSubmissionInterface $webform_submission) {
$states = WebformElementHelper::getStates($element);
$enabled = 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 ($state === 'disabled' && $result === TRUE) {
$enabled = FALSE;
}
}
return $enabled;
}