public function WebformHandlerBase::checkConditions in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformHandlerBase.php \Drupal\webform\Plugin\WebformHandlerBase::checkConditions()
Check handler conditions against a webform submission.
Note: Conditions are only applied to callbacks that require a webform submissions.
Conditions are ignored by…
- \Drupal\webform\Plugin\WebformHandlerInterface::alterElements
- \Drupal\webform\Plugin\WebformHandlerInterface::preCreate
Parameters
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
Return value
bool TRUE if handler is disable or webform submission passes conditions. FALSE if webform submission fails conditions.
Overrides WebformHandlerInterface::checkConditions
File
- src/
Plugin/ WebformHandlerBase.php, line 360
Class
- WebformHandlerBase
- Provides a base class for a webform handler.
Namespace
Drupal\webform\PluginCode
public function checkConditions(WebformSubmissionInterface $webform_submission) {
$hash = $webform_submission
->getDataHash();
if (isset($this->conditionsResultCache[$hash])) {
return $this->conditionsResultCache[$hash];
}
// Return TRUE if conditions are disabled for the handler.
if (!$this
->supportsConditions()) {
$this->conditionsResultCache[$hash] = TRUE;
return TRUE;
}
$conditions = $this
->getConditions();
// Return TRUE if no conditions are defined.
if (empty($conditions)) {
$this->conditionsResultCache[$hash] = TRUE;
return TRUE;
}
// Get conditions.
$state = key($conditions);
$conditions = $conditions[$state];
// Replace tokens in conditions.
$conditions = $this
->replaceTokens($conditions, $webform_submission);
// Validation conditions.
$result = $this->conditionsValidator
->validateConditions($conditions, $webform_submission);
// Negate result for 'disabled' state.
$result = $state === 'disabled' ? !$result : $result;
$this->conditionsResultCache[$hash] = $result;
return $result;
}