You are here

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

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

Set Form API state error.

Parameters

array $element: The form element.

array $errors: An array used to capture errors.

null|string $state: An element state.

null|string $selector: An element selector.

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

File

src/Element/WebformElementStates.php, line 907

Class

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

Namespace

Drupal\webform\Element

Code

protected static function setFormApiStateError(array $element, array &$errors, $state = NULL, $selector = NULL) {
  $state_options = $element['#state_options_flattened'];
  $selector_options = $element['#selector_options_flattened'];
  if ($state && !$selector) {
    $t_args = [
      '%state' => $state_options[$state],
    ];
    $errors[] = t('The %state state is declared more than once. There can only be one declaration per state.', $t_args);
  }
  elseif ($state && $selector) {
    $t_args = [
      '%selector' => $selector_options[$selector],
      '%state' => $state_options[$state],
    ];
    $errors[] = t('The %selector element is used more than once within the %state state. To use multiple values within a trigger try using the pattern trigger.', $t_args);
  }
}