W3cubDocs

/Drupal 8

protected function StorableConfigBase::validateValue

protected StorableConfigBase::validateValue($key, $value)

Validate the values are allowed data types.

Parameters

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

string $value: Value to associate with the key.

Return value

null

Throws

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

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!StorableConfigBase.php/function/StorableConfigBase::validateValue/8.1.x