function StorableConfigBase::validateValue

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Config/StorableConfigBase.php \Drupal\Core\Config\StorableConfigBase::validateValue()
  2. 10 core/lib/Drupal/Core/Config/StorableConfigBase.php \Drupal\Core\Config\StorableConfigBase::validateValue()
  3. 11.x core/lib/Drupal/Core/Config/StorableConfigBase.php \Drupal\Core\Config\StorableConfigBase::validateValue()

Validate the values are allowed data types.

Parameters

string $key: A string that maps to a key within the configuration data.

mixed $value: Value to associate with the key.

Return value

null

Throws

\Drupal\Core\Config\UnsupportedDataTypeConfigException If the value is unsupported in configuration.

3 calls to StorableConfigBase::validateValue()
Config::save in core/lib/Drupal/Core/Config/Config.php
Saves the configuration object.
LanguageConfigOverride::save in core/modules/language/src/Config/LanguageConfigOverride.php
Saves the configuration object.
StorableConfigBase::castValue in core/lib/Drupal/Core/Config/StorableConfigBase.php
Casts the value to correct data type using the configuration schema.

File

core/lib/Drupal/Core/Config/StorableConfigBase.php, line 153

Class

StorableConfigBase
Provides a base class for configuration objects with storage support.

Namespace

Drupal\Core\Config

Code

protected function validateValue($key, $value) {
    // Minimal validation. Should not try to serialize resources or non-arrays.
    if (is_array($value)) {
        foreach ($value as $nested_value_key => $nested_value) {
            $this->validateValue($key . '.' . $nested_value_key, $nested_value);
        }
    }
    elseif ($value !== NULL && !is_scalar($value)) {
        throw new UnsupportedDataTypeConfigException("Invalid data type for config element {$this->getName()}:{$key}");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.