You are here

public static function WebformHeight::validateWebformHeight in Webform 8.5

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

Validates an height element.

File

src/Element/WebformHeight.php, line 233

Class

WebformHeight
Provides a webform height element.

Namespace

Drupal\webform\Element

Code

public static function validateWebformHeight(&$element, FormStateInterface $form_state, &$complete_form) {
  $height_element =& $element['container'];
  if ($height_element['feet']['#value'] === '' && $height_element['inches']['#value'] === '') {
    $value = '';
  }
  else {
    $feet = (double) $height_element['feet']['#value'];
    $inches = (double) $height_element['inches']['#value'];
    $value = $feet * 12 + $inches;
  }
  if (Element::isVisibleElement($element) && $element['#required'] && empty($value)) {
    WebformElementHelper::setRequiredError($element, $form_state);
  }
  $form_state
    ->setValueForElement($height_element['feet'], NULL);
  $form_state
    ->setValueForElement($height_element['inches'], NULL);
  $value = (string) $value;
  $element['#value'] = $value;
  $form_state
    ->setValueForElement($element, $value);
}