protected function RemotePostWebformHandler::castCustomData in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformHandler/RemotePostWebformHandler.php \Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler::castCustomData()
Cast custom data.
Parameters
array $data: Custom data.
Return value
array The custom data with value casted
1 call to RemotePostWebformHandler::castCustomData()
- RemotePostWebformHandler::getRequestData in src/
Plugin/ WebformHandler/ RemotePostWebformHandler.php - Get a webform submission's request data.
File
- src/
Plugin/ WebformHandler/ RemotePostWebformHandler.php, line 756
Class
- RemotePostWebformHandler
- Webform submission remote post handler.
Namespace
Drupal\webform\Plugin\WebformHandlerCode
protected function castCustomData(array $data) {
if (empty($this->configuration['cast'])) {
return $data;
}
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this
->castCustomData($value);
}
elseif (is_string($value) && preg_match('/^\\((int|integer|bool|boolean|float|double|real)\\)\\s*(.+)$/', $value, $match)) {
$type_cast = $match[1];
$type_value = $match[2];
switch ($type_cast) {
case 'int':
case 'integer':
$data[$key] = (int) $type_value;
break;
case 'bool':
case 'boolean':
$data[$key] = (bool) $type_value;
break;
case 'float':
case 'double':
case 'real':
$data[$key] = (double) $type_value;
break;
}
}
}
return $data;
}