You are here

protected function RemotePostWebformHandler::castRequestValue in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformHandler/RemotePostWebformHandler.php \Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler::castRequestValue()

Cast request value.

Parameters

array $element: An element.

\Drupal\webform\Plugin\WebformElementInterface $element_plugin: The element's webform plugin.

mixed $value: The element's value.

Return value

mixed The element's value cast to boolean or float when appropriate.

1 call to RemotePostWebformHandler::castRequestValue()
RemotePostWebformHandler::castRequestValues in src/Plugin/WebformHandler/RemotePostWebformHandler.php
Cast request values.

File

src/Plugin/WebformHandler/RemotePostWebformHandler.php, line 692

Class

RemotePostWebformHandler
Webform submission remote post handler.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

protected function castRequestValue(array $element, WebformElementInterface $element_plugin, $value) {
  if ($element_plugin instanceof BooleanBase) {
    return (bool) $value;
  }
  elseif ($element_plugin instanceof NumericBase) {
    return (double) $value;
  }
  elseif ($element_plugin instanceof WebformCompositeBase) {
    $composite_elements = isset($element['#element']) ? $element['#element'] : $element_plugin
      ->getCompositeElements();
    foreach ($composite_elements as $key => $composite_element) {
      if (isset($value[$key])) {
        $composite_element_plugin = $this->elementManager
          ->getElementInstance($composite_element);
        $value[$key] = $this
          ->castRequestValue($composite_element, $composite_element_plugin, $value[$key]);
      }
    }
    return $value;
  }
  else {
    return $value;
  }
}