You are here

protected static function WebformElementStates::getFormApiStatesCondition in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::getFormApiStatesCondition()

Get FAPI states array condition.

Parameters

array $condition: The condition.

Return value

array Associative array container selector, trigger, and value.

1 call to WebformElementStates::getFormApiStatesCondition()
WebformElementStates::convertElementValueToFormApiStates in src/Element/WebformElementStates.php
Convert an element's submitted value to Form API #states.

File

src/Element/WebformElementStates.php, line 935

Class

WebformElementStates
Provides a webform element to edit an element's #states.

Namespace

Drupal\webform\Element

Code

protected static function getFormApiStatesCondition(array $condition) {
  $selector = $condition['selector'];
  $trigger = $condition['trigger'];
  if ($selector && $trigger) {
    if (in_array($trigger, [
      'value',
      '!value',
    ])) {
      $value = $condition['value'];
    }
    elseif (in_array($trigger, [
      'pattern',
      '!pattern',
      'less',
      'less_equal',
      'greater',
      'greater_equal',
      'between',
      '!between',
    ])) {
      $value = [
        $trigger => $condition['value'],
      ];
      $trigger = 'value';
    }
    else {
      $value = TRUE;
    }
  }
  else {
    $value = '';
  }
  return [
    'selector' => $selector,
    'trigger' => $trigger,
    'value' => $value,
  ];
}