Casts a saved value to a string.
The configuration system only saves strings or arrays. Any scalar non-string value is cast to a string. The one exception is boolean FALSE which would normally become '' when cast to a string, but is manually cast to '0' here for convenience and consistency.
Any non-scalar value that is not an array (aka objects) gets cast to an array.
mixed $value: A value being saved into the configuration system.
string The value cast to a string or array.
public function castValue($value) {
if (is_scalar($value) || $value === NULL) {
// Handle special case of FALSE, which should be '0' instead of ''.
if ($value === FALSE) {
$value = '0';
}
else {
$value = (string) $value;
}
}
else {
// Any non-scalar value must be an array.
if (!is_array($value)) {
$value = (array) $value;
}
// Recurse into any nested keys.
foreach ($value as $key => $nested_value) {
$value[$key] = $this
->castValue($nested_value);
}
}
return $value;
}