You are here

protected static function ConditionalFieldsFormHelper::evaluateGrouping in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/ConditionalFieldsFormHelper.php \Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateGrouping()

Evaluates an array with 'AND', 'OR' and 'XOR' groupings.

Each containing a list of boolean values.

1 call to ConditionalFieldsFormHelper::evaluateGrouping()
ConditionalFieldsFormHelper::evaluateDependencies in src/ConditionalFieldsFormHelper.php
Evaluate a set of dependencies for a dependent field.

File

src/ConditionalFieldsFormHelper.php, line 539

Class

ConditionalFieldsFormHelper
Helper to interact with forms.

Namespace

Drupal\conditional_fields

Code

protected static function evaluateGrouping($groups) {
  $or = $and = $xor = TRUE;
  if (!empty($groups['OR'])) {
    $or = in_array(TRUE, $groups['OR']);
  }
  if (!empty($groups['AND'])) {
    $and = !in_array(FALSE, $groups['AND']);
  }
  if (!empty($groups['XOR'])) {
    $xor = array_sum($groups['XOR']) == 1;
  }
  return $or && $and && $xor;
}