You are here

protected function StorableConfigBase::validateValue in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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 152

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