You are here

protected function WebformSubmissionConditionsValidator::getConditionTargetsVisibility in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionConditionsValidator.php \Drupal\webform\WebformSubmissionConditionsValidator::getConditionTargetsVisibility()

Get the visibility state for all of conditions targets.

Parameters

array $conditions: An associative array containing conditions.

array $elements: An associative array of visible elements.

Return value

array An associative array keyed by target selectors with a boolean state.

1 call to WebformSubmissionConditionsValidator::getConditionTargetsVisibility()
WebformSubmissionConditionsValidator::buildForm in src/WebformSubmissionConditionsValidator.php
Apply form #states to visible elements.

File

src/WebformSubmissionConditionsValidator.php, line 1030

Class

WebformSubmissionConditionsValidator
Webform submission conditions (#states) validator.

Namespace

Drupal\webform

Code

protected function getConditionTargetsVisibility(array $conditions, array $elements) {
  $targets = [];
  $this
    ->getConditionTargetsVisibilityRecursive($conditions, $targets);
  foreach ($targets as $selector) {

    // Ignore invalid selector and return FALSE.
    $input_name = static::getSelectorInputName($selector);
    if (!$input_name) {
      $targets[$selector] = FALSE;
      continue;
    }

    // Check if the input's element is visible.
    $element_key = static::getInputNameAsArray($input_name, 0);
    if (!isset($elements[$element_key])) {
      $targets[$selector] = FALSE;
      continue;
    }
    $targets[$selector] = TRUE;
  }
  return $targets;
}