public function Config::castValue

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.

Parameters

mixed $value: A value being saved into the configuration system.

Return value

string The value cast to a string or array.

1 call to Config::castValue()
Config::set in drupal/core/lib/Drupal/Core/Config/Config.php
Sets value in this config object.

File

drupal/core/lib/Drupal/Core/Config/Config.php, line 279
Definition of Drupal\Core\Config\Config.

Class

Config
Defines the default configuration object.

Namespace

Drupal\Core\Config

Code

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;
}